Findbugs issue with ant

蓝咒 提交于 2019-12-04 04:42:02

问题


findbugs:

[findbugs] Executing findbugs from ant task
[findbugs] Running FindBugs...
[findbugs] java.lang.NoClassDefFoundError: org/apache/bcel/classfile/ClassFormtException
[findbugs] Caused by: java.lang.ClassNotFoundException: org.apache.bcel.classfile.ClassFormatException
[findbugs]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[findbugs]     at java.security.AccessController.doPrivileged(Native Method)
[findbugs]     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[findbugs]     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[findbugs]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[findbugs]     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[findbugs] Could not find the main class: edu.umd.cs.findbugs.FindBugs2.  Program will exit.
[findbugs] Exception in thread "main"

I get this issue on executing findbugs with ant though I kept findbugs and essential jar files in the required folder.

I use findbugs 1.3.2 and bcel 5.2.

How to solve this issue ?

[findbugs] Output saved to bugs/reports/findbugs.xml

回答1:


The findbugs documentation states the following:

Note

It is strongly recommended that you use the Ant task with the version of FindBugs it was included with. We do not guarantee that the Ant task Jar file will work with any version of FindBugs other than the one it was included with.

You do not indicate which version of the ANT task you are using....

I would recommend using a dependency manager like ivy to take care of complex classpaths as follows:

<project name="demo" default="findbugs" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="init" description="Use ivy to manage ANT tasks">
        <ivy:cachepath pathid="findbugs.path">
            <dependency org="com.google.code.findbugs" name="findbugs-ant" rev="2.0.1" conf="default"/>
        </ivy:cachepath>

        <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs.path"/>
    </target>

    <target name="findbugs" depends="init">
        ..
        <findbugs ..
        ..
    </target>

</project>

Finally, it is also worth considering the use of Sonar. The Sonar ANT task manages all the findbugs dependencies for you and also runs other tools like checkstyle and PMD.



来源:https://stackoverflow.com/questions/12744819/findbugs-issue-with-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!