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.
Related
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;
}
}
I had a working sonar/jenkins installation, where sonar was installed on localhost:9000 and jenkins was on localhost:8080. I then wanted to hide those services behind Apache and protect them behind Crowd-authenticated account access.
So first, I relocated Jenkins to localhost:8080/jenkins and proxied it. Which worked.
Then I relocated Sonar to localhost:9000/sonar and proxied it. Which also worked.
But now, when I try to execute the Sonar task from within the build script in Jenkins, I get the following error:
sonar:
[sonar:sonar] Apache Ant version 1.7.1 compiled on April 26 2010
[sonar:sonar] Sonar Ant Task version: 1.2
[sonar:sonar] Loaded from: file:/usr/share/ant/lib/sonar-ant-task-1.2.jar
[sonar:sonar] Sonar work directory: /var/lib/jenkins/jobs/buzzcartes/workspace/.sonar
[sonar:sonar] Sonar server: http://localhost:9000
BUILD FAILED
org.sonar.batch.bootstrapper.BootstrapException: http://localhost:9000/api/server /version
at org.sonar.batch.bootstrapper.Bootstrapper.getServerVersion(Bootstrapper.java:71)
at org.sonar.ant.SonarTask.checkSonarVersion(SonarTask.java:225)
at org.sonar.ant.SonarTask.execute(SonarTask.java:188)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.io.FileNotFoundException: http://localhost:9000/api/server/version
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1610)
at java.net.URLConnection.getContent(URLConnection.java:748)
at org.sonar.batch.bootstrapper.Bootstrapper.remoteContent(Bootstrapper.java:123)
at org.sonar.batch.bootstrapper.Bootstrapper.getServerVersion(Bootstrapper.java:69)
... 18 more
I've updated the configuration in Jenkins to reflect the new location of http://localhost/sonar so I'm not sure where the http://localhost:9000/ is now coming from. I've looked in a variety of config files so far with no joy and Google isn't turning up any good answers so far. Any pointers would be most welcome.
Oh, my sonar task in build.xml looks like this:
<target name="sonar" depends="compile">
<!-- list of mandatory Sonar properties -->
<property name="sonar.sources" value="${basedir}/src" />
<!-- list of optional Sonar properties -->
<property name="sonar.projectName" value="buzzcartes" />
<property name="sonar.binaries" value="${basedir}/build" />
<property name="sonar.tests" value="${basedir}/test" />
<property name="sonar.libraries" value="${basedir}/lib" />
<sonar:sonar key="com.benjasoft:buzzcartes" version="0.1-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant" />
Thanks!
Try so set the sonar.host.url parameter
Maven
<sonar.host.url>http://wherever.sonar.com:9000</sonar.host.url>
Ant
<property name="sonar.host.url" value="http://wherever.sonar.com:9000" />
Strangely it is not documented here, but mentioned in the ant task guide.
I am trying to use Ant and Maven to build a project. I am using testNG for test units. As stated here ( http://testng.org/doc/ant.html ) I have defined the taskdef as follow:
<taskdef resource="testngtasks" classpath="testng.jar"/>
in Ant.
In Maven I have added the following (as stated here: http://testng.org/doc/maven.html)
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.2</version>
</dependency>
Maven is getting the files from maven repository and I have checked the location under /.m2. Now that I am getting the testNG from maven, I should change the taskdef in ant to use this new one in Maven repository. I am not sure how to do that. I have tried the following:
<taskdef resource ="testngtasks" classname="org.testng" />
and
<taskdef resource ="testngtasks" classname="org.testng" classpathref="maven.compile.classpath"/>
and
<taskdef resource ="testngtasks" />
but no success, the second one complains that I shouldn't use classpathref and the first one says that I should specify class. The third one is working kind of, but not completely. It is going thorugh and I guess it passes the taskdef step but it is not executing the tests. Part of the Ant (for third one):
<taskdef resource="testngtasks" />
<target name="test" depends="compile">
<echo message="running tests" />
Part of the Ant output: (note that the echo executed, it is somehow passed the taskdef step)
compile:
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:31: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
test:
[echo] running tests
BUILD FAILED
/home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:84: Problem: failed to create task or type testng
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
I am not sure how to use testNG library in Maven repository to define ( taskdef ) the testngtasks in Ant. Any insights would be highly appreciated
try placing a pathelement property in for the classpath of your taskdef like:
<taskdef resource="testngtasks">
<classpath>
<pathelement path="[path to]/testng.jar"/>
</classpath>
</taskdef>
first hardcode the path for pathelement to make sure it's working for you.
I got it to work by using the following taskdef:
<taskdef resource="testngtasks" classpath="./lib/testng-6.2.jar"/>
When Maven retrieves the jar it will not be named testng.jar. So you will need to rename it to the appropriate jar and update the path to jar.
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.
I am getting the symlink error when i do an ant build. Searched in net and some posts suggested to download junit jar for fixing it. Downloaded junit-4.8.2.jar. Added this jar file to Classpath but still's not working. I tried to include the jar file within the build.xml but still it didn't work out.
<target name="-createDir" description="Creates logs directory">
<mkdir dir="${basedir}/${custServer}/logs" />
<symlink link="${basedir}/${custS}/application.properties" resource="${basedir}/application.properties" />
<symlink link="${basedir}/${custS}/log4j.properties" resource="${basedir}/log4j.properties" />
</target>
-createDir:
BUILD FAILED
file:/home/test1/source/teff/build.xml:28: Could not create task or type of type: symlink.
Ant could not find the task or a class this task relies upon.
ant -v
Apache Ant version 1.5.4 compiled on January 8 2005
Buildfile: build.xml
It looks like the symlink task was introduced in ant version 1.6.0.