我将findbugs安装到我的ant lib目录中,并将以下代码添加到我的主要ANT脚本中:
<target name="findbugs" depends="init">
<findbugs home="C:\\findbugs\\" output="html outputFile="C:\\findbugs\\out.html" jvmargs="-Xms512M">
<sourcePath path="${messageaggregator.src}" />
<class location="${messageaggregator.src}"/>
</findbugs>
</target>
在init目标中调用以下xml:
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
在运行ANT脚本时,我得到的是以下输出:
findbugs: [findbugs] Executing findbugs from ant task [findbugs] Running FindBugs... [findbugs] BCEL class compatability error. [findbugs] The version of class org.apache.bcel.generic.ObjectType found was not compatible with [findbugs] FindBugs. Please remove any BCEL libraries that may be interfering. This may happen [findbugs] if you have an old version of BCEL or a library that includes an old version of BCEL [findbugs] in an "endorsed" directory. [findbugs] Output saved to C:\\findbugs\\out.html
为什么findbugs无效?
答案 0 :(得分:2)
你必须摆脱旧版BCEL的冲突。它可能在您的jre / lib / ext目录中(不好主意),或者您为项目获得的CLASSPATH的一部分,或者可能是Ant / lib的一部分。在任何情况下,您都应该在CLASSPATH中找到所有BCEL JAR,删除它们,并使用FindBugs所需的版本更新它们。
答案 1 :(得分:0)
Java Version 1.6.0_06包含旧的BCEL库。
java版“1.6.0_06” Java(TM)SE运行时环境(版本1.6.0_06-b02) Java HotSpot(TM)客户端VM(版本10.0-b22,混合模式)
一旦我改为1.5.0_17,它对我来说很好。
答案 2 :(得分:0)
我发现xalan:xalan:jar:2.6.0
库(我的项目中org.apache.xmlgraphics:batik-bridge:jar:1.7
库的传递依赖项)包含org.apache.bcel.generic.ObjectType
类(可能是错误的版本)。这个类可能是导致以下错误的类:
[INFO] File Encoding is UTF-8 BCEL class compatability error. The version of class org.apache.bcel.generic.ObjectType found was not compatible with FindBugs. Please remove any BCEL libraries that may be interfering. This may happen if you have an old version of BCEL or a library that includes an old version of BCEL in an "endorsed" directory. [INFO] ------------------------------------------------------------------------ [ERROR] FATAL ERROR [INFO] ------------------------------------------------------------------------ [INFO] Java returned: 1 [INFO] ------------------------------------------------------------------------ [INFO] Trace : Java returned: 1 at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:199) at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:153) at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:149) at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64) at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:784) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170) at org.codehaus.mojo.findbugs.FindBugsGui.execute(FindBugsGui.groovy:163) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
由于编译不需要工件(在我们的例子中),我们只是将其范围更改为Maven runtime
文件中的pom.xml
,此错误消失,mvn clean findbugs:findbugs findbugs:gui
再次起作用(至少对我来说):
... <dependencies> <dependency> <groupId>org.apache.xmlgraphics</groupId> <artifactId>batik-bridge</artifactId> <version>1.7</version> <scope>runtime</scope> </dependency> </dependencies> ...
希望这可以节省某人的屁股......
答案 3 :(得分:-1)
如果findbugs有自己的BCEL版本,为什么我会收到此错误:
[findbugs] Executing findbugs from ant task
[findbugs] Running FindBugs...
[findbugs] The java class is not found: org.apache.bcel.classfile.ClassFormatException
[findbugs] Output saved to C:\\findbugs\\out.html
如果我从findbugs.home目录中删除bcel.jar,则会发生此错误。