I can't get FindBugs to take into account my exclude filter:
In tools/findbugs-exclude.xml:
<FindBugsFilter>
<Match>
<Bug pattern="WMI_WRONG_MAP_ITERATOR,SE_COMPARATOR_SHOULD_BE_SERIALIZABLE,RV_RETURN_VALUE_IGNORED,EI_EXPOSE_REP,EI_EXPOSE_REP2,MS_CANNOT_BE_FINAL,SBSC_USE_STRINGBUFFER_CONCATENATION,SE_BAD_FIELD"/>
</Match>
</FindBugsFilter>
In build.xml:
<findbugs home="${findbugs.home}"
output="html"
outputFile="${findbugs.output.current}"
timeout="1200000"
jvmargs="-Xmx1024m"
effort="max"
excludeFilter="${basedir}/tools/findbugs-exclude.xml">
<auxClasspath>
<fileset dir="${basedir}/lib">
<include name="**/*.jar" />
</fileset>
</auxClasspath>
<sourcePath path="${basedir}/sources" />
<class location="${classes}" />
<fileset dir="${basedir}/build/dist">
<include name="*.jar" />
</fileset>
</findbugs>
FindBugs generates the report properly but it includes everything.
I've had the exact same problem and it was due to a typo in the findbugs-exclude.xml file path.
Try running ant in verbose mode like this:
C:\Workspace\example> ant -verbose
You'll notice something like this in the output:
findbugs:
[findbugs] Executing findbugs FindBugsTask from ant task
[findbugs] Running FindBugs...
[findbugs] Executing 'C:\Workspace\opt\Java\jdk1.8.0_72\jre\bin\java.exe' with arguments:
[findbugs] '-Xmx1024m'
[findbugs] '-Dfindbugs.hostApp=FBAntTask'
[findbugs] '-Dfindbugs.home=C:\Workspace\opt\findbugs-3.0.1'
[findbugs] '-classpath'
[findbugs] 'C:\Workspace\opt\findbugs-3.0.1\lib\findbugs.jar'
[findbugs] 'edu.umd.cs.findbugs.FindBugs2'
[findbugs] '-sortByClass'
[findbugs] '-timestampNow'
[findbugs] '-xml:withMessages'
[findbugs] '-exclude'
[findbugs] 'C:\Workspace\example\tools\findbugs-exclude.xml'
[findbugs] '-auxclasspathFromInput'
[findbugs] '-sourcepath'
[findbugs] 'C:\Workspace\example\src'
[findbugs] '-outputFile'
[findbugs] 'C:\Workspace\example\output\findbugs.xml'
[findbugs] '-exitcode'
[findbugs] 'C:\Workspace\example\cls'
If the -exclude argument is missing add the following to your build.xml to see if the path is correct:
<available property="file.exists" file="${basedir}/tools/findbugs-exclude.xml"/>
<echo>${basedir}/tools/findbugs-exclude.xml exists = ${file.exists}</echo>
Because FindBugsTask.java contains a check to see if the excludeFilter file exists.
public void setExcludeFilter(File filterFile) {
if (filterFile != null && filterFile.length() > 0) {
this.excludeFile = filterFile;
} else {
this.excludeFile = null;
}
}
Related
I am trying to do the code coverage using Jacoco. I have written the Jacoco configuration in ANT script.Jacoco working fine without logs in code.
But it is error out for loggers (apache log4j) added in my code.
I tried to exclude the logs by adding below code in my ant script as <jacoco:coverage destfile="${result.exec.file}" excludes="org.apache.log4j.*">
still it is giving me same error.
I am getting below exception:
15:35:16 [junit] Testcase: testUncoveredMethod took 0.009 sec
15:35:16 [junit] Caused an ERROR
15:35:16 [junit] org/apache/log4j/Category
15:35:16 [junit] java.lang.NoClassDefFoundError: org/apache/log4j/Category
15:35:16 [junit] at com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverage.<clinit>(JacacoCoverage.java:6)
15:35:16 [junit] at com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverageTest.testUncoveredMethod(JacacoCoverageTest.java:23)
15:35:16 [junit] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category
15:35:16 [junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
15:35:16 [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
15:35:16 [junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
15:35:16 [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
Jacoco configuration
<target name="test" depends="compile">
<jacoco:coverage destfile="${result.exec.file}" excludes="org.apache.log4j.*">
<junit showoutput="true" printsummary="on" enabletestlistenerevents="true" fork="true" haltonfailure="no" forkmode="once">
<classpath path="${result.classes.dir}"/>
<classpath path="${junit.jar.path}"/>
<classpath path="${hamcrest.jar.path}"/>
<classpath location="../../ant-junit-1.9.5.jar"/>
<formatter type="plain" usefile="false"/>
<test name="com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverageTest"/>
</junit>
</jacoco:coverage>
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!--
This task needs the collected execution data and ...
-->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}"/>
<csv destfile="${result.report.dir}/report.csv"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>
</target>
I got the fix for this issue. Need to add log4j jar in junit classpath
When I try to call simple JAR file via ANT. Whenever i execute I get the following error:
C:\temp\My\My_Ant.xml:20: Execute failed: java.io.IOException: Cannot run program "C:\PROGRA~1\Java\jre7\bin\java.exe -jar C:\temp\My\javatest.jar" (in directory "C:\temp\My"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:426)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:440)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:629)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:670)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:496)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:854)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 24 more
The Java program is simply printing "hello world!"
I call the ANT in the following way:
C:\Tools\ANT\apache-ant-1.9.7\bin\ant -buildfile My_Ant.xml
Any idea why I am getting this? when I run this via command line I get the correct message.
C:\temp\My>C:\PROGRA~1\Java\jre7\bin\java.exe -jar JavaTest.jar
hello from Java
Edit:
Ant Script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Issue Management" default="startActivity" xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="javaPath" value="C:\PROGRA~1\Java\jre7\bin\java.exe"/>
<property name="AnalyzerPath" value="C:\temp\my"/>
<property name="Analyzer" value="javatest.jar"/>
<!--Setting the location of ANT Contrib starts
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="C:/Tools/ANT/apache-ant-1.8.2/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>-->
<tstamp>
<format property="current.time" pattern="yyyyMMdd_HHmmss" />
</tstamp>
<target name="startActivity">
<echo>Issue Management script started at ${current.time}</echo>
<exec executable="${javaPath} -jar ${AnalyzerPath}\${Analyzer}" resultproperty="BuildErrorCode" failonerror="true" dir="${AnalyzerPath}">
<arg value="--help"/>
</exec>
<echo>Issue Management script ended at ${current.time}</echo>
</target>
</project>
The executable parameter needs to be set to the name or path of just the executable; command arguments should be specified separately using nested <arg> elements, for example:
<exec executable="${javaPath}" resultproperty="BuildErrorCode"
failonerror="true" dir="${AnalyzerPath}">
<arg value="-jar" />
<arg value="${AnalyzerPath}\${Analyzer}" />
<arg value="--help" />
</exec>
When you specified the whole command line as the executable, it was treated as a single command with embedded spaces, and so was not found:
Cannot run program "C:\PROGRA~1\Java\jre7\bin\java.exe -jar C:\temp\My\javatest.jar"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'm trying to following apache's ANT tutorial:
http://ant.apache.org/manual/index.html
I'm currently at the JUnit portion, but I keep getting errors related to not being able to find the junit.framework package.
I believe I've followed the tutorial exactly as follows - Here are the details:
-----My file structure-----
build.xml
/build
../classes
/lib
..log4j-1.2.8.jar
myManifest
/src
..HelloWorldTest.java
..log4j.properties
../oata
....HelloWorld.java
-----Sources-----
myManifest:
Main-Class: oata.HelloWorld
build.xml:
<project name ="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="jar.dir" value="${build.dir}/jar" />
<property name="lib.dir" value="lib" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<property name="main-class" value="oata.HelloWorld" />
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" />
<copy todir="${classes.dir}" >
<fileset dir="${src.dir}" excludes="**/*.java" />
</copy>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="junit" depends="jar">
<junit printsummary="yes">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java"/>
</batchtest>
</junit>
</target>
<target name="clean-build" depends="clean,jar" />
<target name="main" depends="clean,run" />
</project>
HelloWorldTest.java:
public class HelloWorldTest extends junit.framework.TestCase {
public void testNothing() {
}
public void testWillAlwaysFail() {
fail("An error message");
}
}
HelloWorld.java
package oata;
import org.apache.log4j.Logger;
public class HelloWorld {
static Logger logger = Logger.getLogger(HelloWorld.class);
public static void main(String [] args){
logger.info("Hello World!");
}
}
log4j.properties:
log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n
---Output---
ant -verbose junit
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
Trying the default build file: build.xml
Buildfile: /Users/jtyler/Projects/AntHelloWorld/build.xml
Detected Java version: 1.6 in: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Detected OS: Mac OS X
parsing buildfile /Users/jtyler/Projects/AntHelloWorld/build.xml with URI = file:/Users/jtyler/Projects/AntHelloWorld/build.xml
Project base dir set to: /Users/jtyler/Projects/AntHelloWorld
parsing buildfile jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `junit' is [compile, jar, junit]
Complete build sequence is [compile, jar, junit, clean, run, main, clean-build, ]
compile:
[mkdir] Skipping /Users/jtyler/Projects/AntHelloWorld/build/classes because it already exists.
[javac] /Users/jtyler/Projects/AntHelloWorld/build.xml:20: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] HelloWorldTest.java added as HelloWorldTest.class doesn't exist.
[javac] /Users/jtyler/Projects/AntHelloWorld/src/log4j.properties skipped - don't know how to handle it
[javac] oata/HelloWorld.java added as oata/HelloWorld.class doesn't exist.
[javac] Compiling 2 source files to /Users/jtyler/Projects/AntHelloWorld/build/classes
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] '/Users/jtyler/Projects/AntHelloWorld/build/classes'
[javac] '-classpath'
[javac] '/Users/jtyler/Projects/AntHelloWorld/build/classes:/Users/jtyler/Projects/AntHelloWorld/lib/log4j-1.2.8.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-antlr.jar:/usr/share/ant/lib/ant-jmf.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-junit4.jar:/usr/share/ant/lib/ant-swing.jar:/usr/share/ant/lib/ant-testutil.jar:/usr/share/ant/lib/ant.jar'
[javac] '-sourcepath'
[javac] '/Users/jtyler/Projects/AntHelloWorld/src'
[javac] '-g:none'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] Files to be compiled:
[javac] /Users/jtyler/Projects/AntHelloWorld/src/HelloWorldTest.java
[javac] /Users/jtyler/Projects/AntHelloWorld/src/oata/HelloWorld.java
[javac] /Users/jtyler/Projects/AntHelloWorld/src/HelloWorldTest.java:1: package junit.framework does not exist
[javac] public class HelloWorldTest extends junit.framework.TestCase {
[javac] ^
[javac] /Users/jtyler/Projects/AntHelloWorld/src/HelloWorldTest.java:7: cannot find symbol
[javac] symbol : method fail(java.lang.String)
[javac] location: class HelloWorldTest
[javac] fail("An error message");
[javac] ^
[javac] 2 errors
BUILD FAILED
/Users/jtyler/Projects/AntHelloWorld/build.xml:20: Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1150)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
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 org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
Is there something I'm missing that's needed to be included that was (or wasn't) mentioned in the tutorial?
EDIT: Based on Alex's inquiries, I tested to see if I had ant's junit jars in my shared directories (which I do):
$ ls /usr/share/ant/lib/ant-junit*.jar
/usr/share/ant/lib/ant-junit.jar /usr/share/ant/lib/ant-junit4.jar
I also tried to manually put ant-junit, ant-junit4.jar, and junit.jar into my project's lib directory, with the following results (all errors) after running ant clean junit:
junit.jar - /Users/jtyler/Projects/AntHelloWorld/build.xml:45: Reference application not found.
ant-junit.jar: package junit.framework does not exist
ant-junit.jar and ant.junit4.jar: package junit.framework does not exist
ant-junit4.jar: package junit.framework does not exist
EDIT The whole error when only junit.jar is included in the lib folder and calling ant clean junit is:
$ ant clean junit
Buildfile: /Users/jtyler/Projects/AntHelloWorld/build.xml
clean:
[delete] Deleting directory /Users/jtyler/Projects/AntHelloWorld/build
compile:
[mkdir] Created dir: /Users/jtyler/Projects/AntHelloWorld/build/classes
[javac] /Users/jtyler/Projects/AntHelloWorld/build.xml:20: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 2 source files to /Users/jtyler/Projects/AntHelloWorld/build/classes
[copy] Copying 1 file to /Users/jtyler/Projects/AntHelloWorld/build/classes
jar:
[mkdir] Created dir: /Users/jtyler/Projects/AntHelloWorld/build/jar
[jar] Building jar: /Users/jtyler/Projects/AntHelloWorld/build/jar/HelloWorld.jar
junit:
BUILD FAILED
/Users/jtyler/Projects/AntHelloWorld/build.xml:45: Reference application not found.
The tutorial is misleading. The junit files that are included in ant do not work. I downloaded juinit and copied the jar file to the lib folder of the project and it now works fine.
On top of including the junit.jar file within my lib dir, I added the following line to my build.xml file right above the junit task declaration:
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
which is a copy of the 'application' path id declaration within the 'run' task definition.
The application builds successfully, and I get the following output with ant junit (test failure is expected):
ant junit
Buildfile: /Users/jtyler/Projects/AntHelloWorld/build.xml
compile:
[javac] /Users/jtyler/Projects/AntHelloWorld/build.xml:20: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
jar:
junit:
[junit] Running HelloWorldTest
[junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.001 sec
[junit] Test HelloWorldTest FAILED
BUILD SUCCESSFUL
Total time: 1 second
Comments the following questions would be greatly appreciated:
Is the fact I actually needed to include the junit.jar file in my lib folder something I should be concerned about? I would assume this is not necessary if ant's tutorial explicitly states "Because Ant has a built-in JUnit 3.8.2 you could start directly using it."
Is the fact I needed to define the 'application' path id outside of the run task definition a typo within the apache ant tutorial? Or are there other things I missed or should consider?
Thanks to all those that helped.
You must specify junit.jar itself in your compile and in your <junit> task's classpath. This is not automatically included in your compile:
<!-- Contains junit.jar and other needed test classes -->
<path id="junit.classpath">
<fileset dir="${junit.directory}"/>
</path>
<!-- Contains third party jars your code is dependent upon -->
<path id="main.classpath">
<fileset dir="${dependent.jar.dir}"/>
</path>
<!-- Your main Java source code directory -->
<property name="main.srcdir" value="${basedir}/src/main/java"/>
<!-- Your main Junit test directory source code -->
<property name="test.srcdir" value="${basedir}/src/test/java"/>
<!-- Where you're compiling your main classes to -->
<property name="main.destdir" value="${basedir}/target/classes"/>
<!-- Where you're compiling your test classes to -->
<property name="test.destdir" value="${basedir}/target/test-classes"/>
[...]
<!-- Compile Test Classes -->
<!-- Notice you have three classpath elements:
* Your main classes you compiled before
* Your test main classpath that your main classes
were dependent up
* The junit.jar classpath
-->
<javac destdir="${test.destdir}"
srcdir="${test.srcdir}">
<classpath>
<!-- Your non-test classes you compiled before -->
<pathelement path="${main.destdir}/>
</classpath>
<classpath refid="junit.classpath"/>
<classpath refid="main.classpath"/>
</javac>
<!-- Now run your unit tests: Note how you have the same
three classpath elements as before -->
<junit fork="yes">
<classpath>
<pathelement path="${main.destdir}"/>
<pathelement path="${test.destdir}"/>
</classpath>
<classpath refid="main.classpath"/>
<classpath refid="junit.classpath"/>
[...]
</junit>
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
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.
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>
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.
It looks like a installation/configuration of findbugs with ant.
From the snippet above, it looks like the findbugs has been installed in lib subfolder of ant, rather than just findbugs-ant.jar being copied to it as documented.