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

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.

Related

Ant: java.sql.SQLException: unable to open database file

I try to build my java project by Ant.
Windows 7 Professional (64 bit), Java 1.8.
I run my custom ant's target:
ant create-dist-win-lite -Denvironment=development
Here build.xml
<target name="create-dist-win-lite" description="Create WIN Lite dinstribute">
<ac:var name="var.distribute.os.family" value="${prop.distribute.os.family.win}" />
<ac:var name="var.distribute.version.type" value="${prop.distribute.version.lite}" />
<ac:runtarget target="create-dist-os" />
</target>
<target name="db:sqlite-exec-queries" depends="db:sqlite-set-variables,db:set-db-url">
<echo message="var.data.dir.name=${var.data.dir.name}" />
<echo message="var.db.driver=${var.db.driver}" />
<echo message="var.db.current.url=${var.db.current.url}" />
<echo message="var.db.lib.file.name=${var.db.lib.file.name}" />
<delete dir="${var.data.dir.name}" />
<mkdir dir="${var.data.dir.name}" />
<sql driver="${var.db.driver}" url="${var.db.current.url}" userid="${var.db.user}" password="${var.db.pwd}" classpath="${lib.dir.name}/${var.db.lib.file.name}" delimiter="${var.db.delimiter}">
<transaction src="${db.dir}/${var.db.type}/create-tables.sql" />
<transaction src="${db.dir}/${var.db.type}/insert-data.sql" />
</sql>
</target>
As result, success created empty sqlite db file in c:\dev\ca\dist\data\ca.db.
But the folder c:\dev\ca\dist\data is READ only.
But target not success finish. When execute target db:sqlite-exec-queries I get error in this line:
<sql driver="${var.db.driver}" url="${var.db.current.url}" userid="${var.db.user}" password="${var.db.pwd}" classpath="${lib.dir.name}/${var.db.lib.file.name}" delimiter="${var.db.delimiter}">
Here full ant log:
db:sqlite-exec-queries:
[echo] var.data.dir.name=dist/data
[echo] var.db.driver=org.sqlite.JDBC
[echo] var.db.current.url=jdbc:sqlite://c:\dev\ca\dist\data/ca.db
[echo] var.db.lib.file.name=sqlitejdbc-v056.jar
[delete] Deleting directory c:\dev\ca\dist\data
[mkdir] Created dir: c:\dev\ca\dist\data
[sql] Executing resource: c:\dev\ca\db\sqlite\create-tables.sql
[sql] Failed to execute: CREATE UNIQUE INDEX [AccountStatuses_Index] ON [AccountStatuses]( [CODE] ASC )
BUILD FAILED
c:\dev\ca\build.xml:1396: java.sql.SQLException: unable to open database file
at org.sqlite.DB.execute(DB.java:275)
at org.sqlite.Stmt.exec(Stmt.java:56)
at org.sqlite.Stmt.execute(Stmt.java:83)
at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:775)
at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:745)
at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1055)
at org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:985)
at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:653)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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 net.sf.antcontrib.logic.RunTargetTask.execute(RunTargetTask.java:48)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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.taskdefs.Sequential.execute(Sequential.java:68)

FindBugs Exclude filter with Ant

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;
}
}

SONAR - java.lang.IllegalStateException: Infinite loop in property interpolation of ${SQLSCRIPT}: SQLSCRIPT

I have very simple Sonar configuration with Ant task:
<target name="upload_to_sonar">
<property name="sonar.jdbc.url" value="jdbc:oracle:thin:#server:1521:sid"/>
<property name="sonar.host.url" value="http://sonar:80"/>
<property name="sonar.jdbc.username" value="SONAR"/>
<property name="sonar.jdbc.password" value="SONAR"/>
<property name="sonar.projectKey" value="test"/>
<property name="sonar.projectName" value="test"/>
<property name="sonar.projectVersion" value="trunk"/>
<property name="sonar.language" value="java"/>
<property name="sonar.sources" value="sources_for_sonar"/>
<property name="sonar.binaries" value="classes_for_sonar"/>
<taskdef name="sonar" classname="org.sonar.ant.SonarTask">
<classpath path="${EXTERNAL}/sonar-ant-task-2.0.jar" />
</taskdef>
<sonar/>
</target>
Those folders contain sources and classes in root level.
For some reason execution gives me following error no matter how I configure it:
Buildfile: D:\trunk\src\build.xml
upload_to_sonar:
[sonar:sonar] Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[sonar:sonar] Sonar Ant Task version: 2.0
[sonar:sonar] Loaded from: file:/D:/trunk/src/./sources/external/sonar-ant-task-
2.0.jar
[sonar:sonar] Sonar work directory: D:\trunk\src\.sonar
[sonar:sonar] Sonar server: http://sonar:80
BUILD FAILED
D:\trunk\src\build.xml:132: org.sonar.runner.RunnerException: java.lang.IllegalS
tateException: Infinite loop in property interpolation of ${SQLSCRIPT}: SQLSCRIP
T
at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
at org.sonar.runner.Runner.execute(Runner.java:151)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:93)
at org.sonar.ant.SonarTask.execute(SonarTask.java:75)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a: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(DefaultExe
cutor.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)
Caused by: java.lang.IllegalStateException: Infinite loop in property interpolat
ion of ${SQLSCRIPT}: SQLSCRIPT
at org.apache.commons.lang.text.StrSubstitutor.checkCyclicSubstitution(S
trSubstitutor.java:701)
at org.apache.commons.lang.text.StrSubstitutor.substitute(StrSubstitutor
.java:645)
at org.apache.commons.lang.text.StrSubstitutor.substitute(StrSubstitutor
.java:656)
at org.apache.commons.lang.text.StrSubstitutor.substitute(StrSubstitutor
.java:563)
at org.apache.commons.lang.text.StrSubstitutor.replace(StrSubstitutor.ja
va:305)
at org.apache.commons.configuration.PropertyConverter.interpolate(Proper
tyConverter.java:958)
at org.apache.commons.configuration.AbstractConfiguration.interpolate(Ab
stractConfiguration.java:446)
at org.apache.commons.configuration.CompositeConfiguration.getList(Compo
siteConfiguration.java:312)
at org.apache.commons.configuration.AbstractConfiguration.getList(Abstra
ctConfiguration.java:1109)
at org.apache.commons.configuration.CompositeConfiguration.getStringArra
y(CompositeConfiguration.java:320)
at org.sonar.batch.Batch.convertToProperties(Batch.java:89)
at org.sonar.batch.Batch.create(Batch.java:78)
at org.sonar.runner.internal.batch.Launcher.executeBatch(Launcher.java:6
8)
at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.sonar.runner.Runner.delegateExecution(Runner.java:285)
... 19 more
Total time: 1 minute 12 seconds
SONAR server version is 3.2
Ant task version 2.0
Enabling verbosity don't give any additional details whatsoever
Created a ticket for community http://jira.codehaus.org/browse/SONARPLUGINS-2704

Findbugs issue with ant

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.

ClassNotFoundException on a JUNIT ant script

I have written few test scripts using JUnit 4 and Selenium.
I have added the jar files for JUnit and Selenium to eclipse and if I run my tests through eclipse IDE everything is working as expected.
I am now trying to run these tests through the ant script below:
<project name="JUnit" default="test">
<property name="src" value="./src" />
<property name="classes" value="./classes" />
<property name="test.class.name" value="AllTests" />
<path id="test.classpath">
<pathelement location="${classes}" />
<pathelement location="C:/Program Files/eclipse 3.5/plugins/org.junit4_4.5.0.v20090824/junit.jar" />
<pathelement location="C:/selenium/selenium-server-standalone-2.0b2.jar" />
<pathelement location="C:/Program Files/eclipse 3.5/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar" />
</path>
<target name="test">
<junit fork="yes" haltonfailure="yes">
<test name="${test.class.name}" />
<formatter type="plain" usefile="false" />
<classpath refid="test.classpath" />
</junit>
</target>
</project>
The problem is that when I run this ant script I am getting the following Exception:
[junit] java.lang.ClassNotFoundException: AllTests
[junit] at java.net.URLClassLoader$1.run(Unknown Source)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Unknown Source)
I have added all the jar files that I see in eclipse .classpath file so a bit confused of which files I am missing.
Found the problem, stupid one but I guess it was lack of concentration...
My .class files are in the ./bin folder and the ant script was pointing to ./classes.
I copied it from an old ant script I've been using and didn't take notice of the properties configured.

Resources