필자는 필자의 커맨드 라인 Ant 빌드의 일부로 FindBugs (2.0.1)를 실행하려고합니다. 아래FindBugs는 클래스 패스에서 bcel jar를 찾지 않습니다.
당신이 스크린 샷에서 볼 수 있듯이 : 나는 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 bcel-1.0.jar
이라는 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에 복사하여 액세스 가능하게 만들었습니다 (Eclipse에 내장 된 Ant 인스턴스 대신) 명령 행에서 실행되는 Ant 버전으로 변경한다.
<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>
하지만 명령 줄에서 ant -buildfile build.xml echoMsg
를 실행할 때, 내가 FindBugs에 오류 얻을 :
/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/
build.xml
내부의
내 프로젝트 디렉토리 구조는
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!!!
여기 내게 어떤 것이 있습니다 깜짝 놀라게 :
이- 에도
failOnError="true"
로, FindBugs이 런타임 예외가 출력 - 마지막 조각을 발견 심지어 빌드를 중단하지 않습니다 "
Output saved to gen/audits/qual/findbugs.html
는"거짓말! 이 없습니다. :gen/audits/qual
! bcel-1.0.jar
은 lib/디렉토리에있는 다른 모든 JAR와 마찬가지로 FindBugs 홈 아래에 있습니다.
을 참고 : findbugs-ant.jar
가 확실히 ANT_HOME/lib 디렉토리에 복사됩니다; 그렇지 않으면 Ant 태스크를 찾을 수 없다는 불평을하면서 실패한 빌드를 얻게 될 것입니다. 온전한 검사로서, 나는 앞서 가서 (ANT_HOME/lib에서 findbugs-ant.jar
을 삭제하고 실패한 빌드를 얻었습니다.) 이 빌드는 실패하지 않습니다 (성공합니다!). 그것은 findbugs를 실행하지 않습니다.
아무도 여기에서 무슨 일이 일어나고 있는지 알아볼 수 있습니까? 미리 감사드립니다!
는 http://stackoverflow.com/questions/12744819/findbugs-issue-with-ant/ –