[英]Why does Cobertura seem to switch my Eclipse's Java version?
These are the steps that create the error: 这些是导致错误的步骤:
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.