对于我的生活,我试图让FindBugs(2.0.1)作为我的命令行Ant构建的一部分运行.我下载了FindBugs JAR并将其解压缩到/home/myuser/java/repo/umd/findbugs/2.0.1/findbugs-2.0.1:

正如您在屏幕截图中看到的,在/home/myuser/java/repo/umd/findbugs/2.0.1/findbugs-2.0.1/lib下有一个JAR被调用bcel-1.0.jar,如果你打开它,你可以看到我已经钻到了一个叫做的班级org.apache.bcel.classfile.ClassFormatException.坚持这个想法.
然后我将/home/myuser/java/repo/umd/findbugs/2.0.1/findbugs-2.0.1/lib/findbugs-ant.jar复制到$ {env.ANT_HOME}/lib,以使其可以访问从命令行运行的Ant(而不是内置到Eclipse中的Ant实例).
我的项目目录结构如下:
/home/myuser/sandbox/workbench/eclipse/workspace/myapp/
src/
main/
java/
test/
java/
build/
build.xml
build.properties
gen/
bin/
main/ --> where all main Java class files compiled to
test/ --> where all test Java class files compiled to
audits/
qual/
staging/
Run Code Online (Sandbox Code Playgroud)
内部build.xml:
<project name="myapp-build" basedir=".." default="package"
xmlns:fb="antlib:edu.umd.cs.findbugs">
<path id="findbugs.source.path">
<fileset dir="src/main/java">
<include name="**.*java"/>
</fileset>
<fileset dir="src/main/test">
<include name="**.*java"/>
</fileset>
</path>
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
uri="antlib:edu.umd.cs.findbugs"/>
<!-- Other Ant target omitted for brevity. -->
<target name="run-findbugs">
<!-- Create a temp JAR that FindBugs can use for analysis. -->
<property name="fb.tmp.jar" value="gen/staging/${ant.project.name}-findbugs-temp.jar"/>
<echo message="Creating ${fb.tmp.jar} for FindBugs."/>
<jar destfile="gen/staging/${ant.project.name}-findbugs-temp.jar">
<fileset dir="gen/bin/main" includes="**/*.class"/>
<fileset dir="gen/bin/test" includes="**/*.class"/>
</jar>
<echo message="Conducting code quality tests with FindBugs."/>
<fb:findbugs home="/home/myuser/java/repo/umd/findbugs/2.0.1/findbugs-2.0.1"
output="html" outputFile="gen/audits/qual/findbugs.html" stylesheet="fancy-hist.xsl" failOnError="true">
<sourcePath refid="findbugs.source.path"/>
<class location="${fb.tmp.jar}"/>
</fb:findbugs>
</target>
<target name="echoMsg" depends="run-findbugs">
<echo message="The build is still alive!!!"/>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
但是当我从命令行运行时ant -buildfile build.xml echoMsg,我在FindBugs中出现错误:
run-findbugs:
[echo] Creating gen/staging/myapp-build-findbugs-temp.jar for FindBugs.
[jar] Building jar: /home/myuser/sandbox/workbench/eclipse/workspace/myapp/gen/staging/myapp-build-findbugs-temp.jar
[echo] Conducting code quality tests with FindBugs.
[fb:findbugs] Executing findbugs from ant task
[fb:findbugs] Running FindBugs...
[fb:findbugs] Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/bcel/classfile/ClassFormatException
[fb:findbugs] Caused by: java.lang.ClassNotFoundException: org.apache.bcel.classfile.ClassFormatException
[fb:findbugs] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[fb:findbugs] at java.security.AccessController.doPrivileged(Native Method)
[fb:findbugs] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[fb:findbugs] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[fb:findbugs] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[fb:findbugs] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[fb:findbugs] Could not find the main class: edu.umd.cs.findbugs.FindBugs2. Program will exit.
[fb:findbugs] Java Result: 1
[fb:findbugs] Output saved to gen/audits/qual/findbugs.html
echoMsg:
[echo] The build is still alive!!!
Run Code Online (Sandbox Code Playgroud)
这让我感到惊讶:
failOnError="true",即使遇到此运行时异常,FindBugs也不会停止构建Output saved to gen/audits/qual/findbugs.html"是谎言!有没有在gen/audits/qual!bcel-1.0.jar绝对FindBugs的下家,就像在lib /目录中的所有其他JAR.请注意:findbugs-ant.jar肯定会复制到ANT_HOME/lib; 否则我会得到一个失败的构建抱怨它无法找到Ant任务.作为一个完整性检查,我继续做了这个(我findbugs-ant.jar从ANT_HOME/lib中删除了一个失败的构建).这个构建不会失败(它成功!).它只是不运行findbugs.
谁能发现这里发生了什么?提前致谢!
有趣的是,因为我使用相同版本的 Findbugs 并且 jar 文件名为bcel.jarnot bcel-1.0.jar。我还从Ant脚本运行 Findbugs。尽管听起来很疯狂,但请尝试再次下载 Findbugs,将其解压到当前的位置,然后再次运行脚本。
| 归档时间: |
|
| 查看次数: |
2727 次 |
| 最近记录: |