简体   繁体   English

为什么Cobertura似乎切换了Eclipse的Java版本?

[英]Why does Cobertura seem to switch my Eclipse's Java version?

These are the steps that create the error: 这些是导致错误的步骤:

  1. Run my unit tests within Eclipse (Cntrl-F11). 在Eclipse(Cntrl-F11)中运行我的单元测试。 All 67 succeed and report as such. 所有67个都成功了,并以此报告。
  2. Using an Ant build.xml file, run a Cobertura task to generate a coverage report. 使用Ant build.xml文件,运行Cobertura任务以生成一份覆盖率报告。 The task fails stating that a unit test has failed. 任务失败,说明单元测试失败。
  3. When I try to run the unit tests using Eclipse again, I receive the following error: 当我尝试再次使用Eclipse运行单元测试时,收到以下错误:

Unsupported major.minor version 51.0

(These symptoms persist until I use Project -> Clean within Eclipse.) (这些症状一直持续到我在Eclipse中使用Project-> Clean为止。)

My Cobertura ant task is: 我的Cobertura蚂蚁任务是:

<target name="report-test" description="Generate a test coverage report." depends="clean, compile">
        <taskdef resource="tasks.properties">
            <classpath>
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/cobertura.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/asm-3.0.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/asm-tree-3.0.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/log4j-1.2.9.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/jakarta-oro-2.0.8.jar" />
            </classpath>
        </taskdef>
        <cobertura-instrument todir="${build.dir}/cobertura-instrument">
            <fileset dir="${build.dir}">
                <include name="**/*.class"/>
            </fileset>
        </cobertura-instrument>
        <junit printsummary="yes" fork="true" haltonfailure="yes" showoutput="yes">
            <classpath location="${build.dir}/cobertura-instrument"/>
            <classpath location="${build.dir}"/>
            <classpath refid="classpath.test" />
            <sysproperty key="net.sourceforge.cobertura.datafile" file="cobertura.ser"/>
            <formatter type="xml" />
            <batchtest todir="doc/junit">
                <fileset dir="${test.dir}" />
            </batchtest>
        </junit>
        <cobertura-report srcdir="${src.dir}" destdir="doc/coverage" format="xml" />
        <delete file="cobertura.ser"/>
    </target>

Coberatura hasn't switched Eclipse's Java version. Coberatura尚未切换Eclipse的Java版本。

What it has actually done is recompile the classes using a version of Java that is more recent than the one you are using to run Eclipse. 它实际上所做的是使用一种比您用来运行Eclipse的Java更新的Java版本重新编译类。 Eclipse can't load those .class files. Eclipse无法加载这些.class文件。

The short term solution is to get Eclipse to clean and rebuild the project(s) after running Coberatura ... as you are currently doing. 短期解决方案是让Eclipse在运行Coberatura之后清理并重建项目,就像您目前正在做的那样。

In the long term, you should either change Eclipse to run using the same Java version as your Ant builds, or change the Ant build file so that it doesn't write the ".class" files into the Eclipse workspace. 从长远来看,您应该更改Eclipse以使其使用与您的Ant构建相同的Java版本运行,或者更改Ant构建文件,以免将“ .class”文件写入Eclipse工作区。 Or both ... 'cos having something else writing stuff into the Eclipse workspace is going to cause other problems too. 或两者兼而有之,因为其他东西在Eclipse工作区中写入内容也会导致其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的Eclipse插件显示在Eclipse RCP版本中,而不显示在Java和Java EE等其他版本中? - Why does my Eclipse plugin show up in Eclipse RCP version, but not in other versions like Java and Java EE? 为什么Cobertura在运行Eclipse插件时报告0%的覆盖率? - Why does Cobertura report 0% coverage when run through the Eclipse plugin? MongoDB Java客户端-为什么`sort`似乎破坏了我的查询? - MongoDB Java client - why does `sort` seem to break my query? 如果Java“随处可见”,为什么Windows会有eclipse / netbeans版本 - Why there's a eclipse/netbeans version for Windows if java “run everywhere” 为什么Eclipse执行我的Java程序的旧版本? - Why is Eclipse executing an older version of my Java program? Java(Eclipse)似乎无法处理我的大型迭代! EULER&#39;S 7的扰流板 - Java (Eclipse) Can't seem to handle my large iterations! SPOILERS FOR EULER'S 7TH 为什么我的日食不生成R.java文件? - Why does my eclipse does not produce the R.java file? 日食中的cobertura - cobertura in eclipse 为什么eclipse不会将编译器切换到Java 8? - Why won't eclipse switch the compiler to Java 8? 为什么 Java 的 ArrayList 的 remove function 似乎花费这么少? - Why does Java's ArrayList's remove function seem to cost so little?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM