java.lang.ClassNotFoundException: edu.umd.cs.findbugs.FindBugs2

10,151

In your taskdef, use the classpath attribute to specify where exactly the jar that contains findbugs class (FindBugsTask) is located. Try something like this:

<taskdef name="findbugs" classpath="C:\apache-ant-1.7.1\lib\findbugsant\findbugs-ant.jar" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" />

The findbugs jar I have is findbugs-ant.jar, so check this out in the proposed solution and use the findbugs filename that applies to your case, and you should be ok.

Share:
10,151
CodeRocker
Author by

CodeRocker

Updated on June 05, 2022

Comments

  • CodeRocker
    CodeRocker almost 2 years

    Getting following exceptions while running findbugs in ant task.
    I have findbugs jar of 0.7 version and jsr305 jar of 1.3.8 version in my findbugs home. Let me know if i am missing anything
    findbugs:

    [findbugs] Executing findbugs from ant task
    [findbugs] Running FindBugs...
    [findbugs] java.lang.NoClassDefFoundError: edu/umd/cs/findbugs/FindBugs2
    [findbugs] Caused by: java.lang.ClassNotFoundException: edu.umd.cs.findbugs.FindBugs2
    [findbugs] at java.net.URLClassLoader$1.run(Unknown Source)
    [findbugs] at java.security.AccessController.doPrivileged(Native Method)
    [findbugs] at java.net.URLClassLoader.findClass(Unknown Source)
    [findbugs] at java.lang.ClassLoader.loadClass(Unknown Source)
    [findbugs] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    [findbugs] at java.lang.ClassLoader.loadClass(Unknown Source)
    [findbugs] Could not find the main class: edu.umd.cs.findbugs.FindBugs2. Program will exit.
    [findbugs] Exception in thread "main"
    [findbugs] Output saved to findbugs.xml

    <property name="build" value="C:\.hudson\jobs\project\workspace\child\classes" />
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/> 
    <target name="findbugs" >
        <findbugs home="C:\apache-ant-1.7.1\lib\findbugsant" 
                  output="xml" 
                  outputFile="findbugs.xml"> 
            <sourcePath path="C:\.hudson\jobs\project\workspace"/> 
            <class location="${build}" /> 
        </findbugs> 
    </target>
    
  • datv
    datv almost 7 years
    This should be the accepted answer. That findbugs jar may have a different name, depending on the package it came with. e.g. C:\workspace\3rdPartyJars\findbug