I am building this project https://github.com/oracle/visualvm . I have JDK10 in my system. I changed the source and target option in build xml to 1.8 from 1.5, as there were error saying 1.5 is not supported anymore. Now, I am getting a compile error pointing to common.xml which is in some other sub-folder.
I have no idea, what is wrong as the error log is also very vague. Also, I am working with Ant for the first time.
Here is the log.
C:\dev\jvisualvm\visualvm\visualvm\netbeans\harness\suite.xml:163: The following error occurred while executing this line:
C:\dev\jvisualvm\visualvm\visualvm\netbeans\harness\common.xml:200: Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1425)
at org.netbeans.nbbuild.CustomJavac.compile(CustomJavac.java:102)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1133)
at org.netbeans.nbbuild.CustomJavac.execute(CustomJavac.java:83)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:225)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
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:834)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
The part of common.xml where the error is thrown looks like this. (nb-javac srcdir tag)
<target name="compile" depends="init,up-to-date" unless="is.jar.uptodate">
<mkdir dir="${build.classes.dir}"/>
<depend srcdir="${src.dir}" destdir="${build.classes.dir}" cache="${build.dir}/depcache">
<classpath refid="cp"/>
</depend>
<property name="javac.fork" value="false"/>
<nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8"
deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="1.8" target="1.8" includeantruntime="false"
fork="false">
<classpath refid="cp"/>
<compilerarg line="${javac.compilerargs}"/>
<processorpath refid="processor.cp"/>
</nb-javac>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${jar-excludes}"/>
</copy>
<processjsannotation classes="${build.classes.dir}" asm="${asm.jar}">
<classpath refid="cp"/>
</processjsannotation>
</target>
Can anyone point me to some direction to resolve this?
You need to build VisualVM with JDK 8. https://github.com/oracle/visualvm clearly mentions it in Get the tools section.
Related
I have a Java project that builds with Maven but has a build.xml with its only task to run maven to copy files. I can't change this project's design but have to get it running in my Intellij IDE. I'm using the bundled Maven and Ant versions. Maven runs fine and compiles the jars, the ant job does not.
<project name="projectAppUploader" default="devbuild">
<target name="devbuild">
<exec executable="mvn">
<arg value="package"/>
</exec>
<copy file="module-gui/target/appUploader-GUI.jar" todir="/foo/bar/GUI/"/>
<copy file="module-main/target/appUploader.jar" todir="/foo/bar/app"/>
</target>
When I run this as an Ant target I get an error:
/home/alex/dev/projectAppUploader/build.xml:3: Execute failed: java.io.IOException: Cannot run program "mvn" (in directory "/home/alex/dev/projectAppUploader/"): error=2, No such file or directory
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:673)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:497)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
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:834)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.Main.start(Main.java:190)
at org.apache.tools.ant.Main.main(Main.java:274)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:31)
Caused by: java.io.IOException: Cannot run program "mvn" (in directory "/home/alex/dev/projectAppUploader/"): error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
at java.base/java.lang.Runtime.exec(Runtime.java:592)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:424)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:438)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:630)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:669)
... 23 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
... 30 more
Ant build completed with 3 errors and no warnings in 0s at 16.04.21, 21:42
Credit goes to dariosiciliy. Ant does not know the path to the executable of the intellij's mvn program. if I add it (or if I install maven on the system and put it into the path variable), it works.
I am using Ant to run my Java application. I have my main in Subscriber class which uses other libraries. So I wanted to run the Controller.Subscriber. But I get the following bug:
[java] Error: A JNI error has occurred, please check your installation and try again
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/paho/client/mqttv3/MqttCallback
[java] at java.lang.Class.getDeclaredMethods0(Native Method)
[java] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
[java] at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
[java] at java.lang.Class.getMethod0(Class.java:3018)
[java] at java.lang.Class.getMethod(Class.java:1784)
[java] at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
[java] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
[java] Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttCallback
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 7 more
[java] Java Result: 1
My Ant file is the following:
<project default="run">
<target name="run">
<java classname="Controller.Subscriber" fork="true">
<classpath>
<pathelement path="target/classes"/>
</classpath>
</java>
</target>
</project>
The path to the Subscriber class: target/classes/Controller/Subscriber.class
What am I doing wrong? Do I have to first to create jar file from my class files to can run the java program or can I execute the class files? Or do I miss a parameter in my java command?
I also tried the following Ant file by giving explicit classpath:
<project default="run">
<target name="run">
<java classname="Controller.Subscriber" fork="true" classpath="classpath">
<classpath>
<pathelement path="target/classes"/>
</classpath>
</java>
</target>
<path id="classpath">
<fileset dir="target">
<include name="*.jar"/>
</fileset>
</target>
</project>
But I am getting the same error message.
I have found the solution to the problem: I have to use classpathref instead of classpath. For some reason classpath="classpath" does not read the id "classpath". But classpathref solved the problem.
I am using ant 1.9.0 to run my Java project.i have a bat file which has command ant clean compile run.the clean and compile is working but for the target run I am getting below error
C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefFoundErrorjunit/framework/TestListener
I am attaching the build.xml please let me know the issue in my build.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="MyMavenProject" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${user.home}/.m2/repository/"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${test.dest}/test_reports"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${ws.jars}">
<include name="*.jar"/>
</fileset>
</path>
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="**/*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.run">
<fileset dir="${ws.jars}" includes="**/*.jar"/>
</path>
<target name="run" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}" includes="**/*"/>
</delete>
<java jar="${ws.jars}" fork="true" spawn="true" />
<junit fork="yes" haltonfailure="no" printsummary="yes">
<classpath refid="test.run" />
<!-- <classpath ="${test.classpath}"/> -->
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<!--include name="tests/LoginTest.class" />
<include name="tests/Parameterized_Test.class" />
<include name="tests/TestApplication.class" /-->
<include name="com/testing/GoogleTest.class" />
<include name="com/testing/YahooTest.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="testcase.path" />
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reportsDir}" />
</junitreport>
</target>
below is the error:
C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefF
oundError: junit/framework/TestListener
[exec] at java.lang.ClassLoader.defineClass1(Native Method)
[exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[exec] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[exec] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[exec] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1385)
[exec] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoaderjava:1064)
[exec] at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at java.lang.ClassLoader.defineClass1(Native Method)
[exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[exec] at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
[exec] at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1299)
[exec] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1354)
[exec] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoaderjava:1315)
[exec] at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:52)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at java.lang.Class.forName0(Native Method)
[exec] at java.lang.Class.forName(Class.java:266)
[exec] at
org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:286)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1653)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmCrash(JUnitTask.java:1617)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1099)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:851)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
[exec] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[exec] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[exec] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[exec] at java.lang.reflect.Method.invoke(Method.java:601)
[exec] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[exec] at org.apache.tools.ant.Task.perform(Task.java:348)
[exec] at org.apache.tools.ant.Target.execute(Target.java:435)
[exec] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[exec] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
[exec] at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
[exec] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[exec] at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
[exec] at org.apache.tools.ant.Main.runBuild(Main.java:851)
[exec] at org.apache.tools.ant.Main.startAnt(Main.java:235)
[exec] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[exec] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
[exec] Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] ... 48 more
[exec]
[exec] Total time: 7 seconds
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.773s
[INFO] Finished at: Mon Jul 07 03:01:39 IST 2014
[INFO] Final Memory: 7M/18M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:
run (default) on project MyMavenProject: An Ant BuildException has occured: exec
returned: 1
[ERROR] around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" e
xecutable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="
true">... # 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build
-runtheapp.xml
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project MyMaven
Project: An Ant BuildException has occured: exec returned: 1
around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executabl
e="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true">..
. # 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runthea
pp.xml
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
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:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException
has occured: exec returned: 1
around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true">..
. # 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runtheapp.xml
this appears to be a known bug in ANT 1.9.0. see here: Bamboo Ant Task fails when running junit task
read comments #4, #5, #8 & #20 # THIS Link for some help.
The ANT manual describes how the junit task requires an extra jar. This can be downloaded from Maven Central
List of junit versions
And installed in the following directory:
$HOME/.ant/lib
Personally I use an ANT plugin called ivy to manage my build's dependencies, see:
Class not found with Ant, Ivy and JUnit - error in build.xml?
Use Ant in netbeans to dynamically fetch latest versions of external libraries during build
Take a look at your error message:
C:\Users\Susanta\MyMaven\MyMavenProject\build] on class \
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: \
java.lang.NoClassDefFoundError junit/framework/TestListener
Note the NoClassDefFoundError which means Ant couldn't find the class being referenced by one of your tasks. Was there a line number associated with this error? There should have been one pointing to the line that contains your <junit/> task. Even without that, you see that the class not found is junit/framework/TestListener.
The error messages in Java applications can be a bit intimidating because you see dozens, maybe hundreds of lines of stack trace. However, think of a Java program crash as a car accident. A car might have gone careening off the road, hit a telephone pole, bounced off that, hit another car, bounced off that, knocked over a fire hydrant, etc. You see a long trail of damage, but if you look at the first place where the accident occurred, you can usually see the problem (Look, there's a banana peel on the road!)
The same is true in Java error messages. The first line will usually tell you exactly what you need to know, and the exceptions are pretty easy to read. In this case, NoClassDefFoundError and it points to junit as the culprit. The next time you see something like this, you'll know what to look for.
As pointed out by Mark O'Connor, the jars needed for the JUnit task is not included with Ant. In fact, a lot of the defined tasks don't have the required jars to run those tasks, as you can see in this table (and <junit> is the fourth item in that table).
In the Ant manual on JUunit task, it states you can do the following:
Note: You must have junit.jar available. You can do one of:
Put both junit.jar and ant-junit.jar in ANT_HOME/lib.
Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable.
Add both JARs to your classpath using -lib.
Specify the locations of both JARs using a <classpath> element in a <taskdef> in the build file.
Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the passed to . (since Ant 1.7)
I personally prefer that last one. I usually place junit.jar in ${basedir}/antlib/junit. This way, when someone checks out my project, they get junit with it.
In the Ant FAQ it discusses some issues with <junit>.
When I build with ant my project that uses libgdx, I get a strange error. It says that a class com.google.gwt.dom.client.ImageElement is not found, but it isn't used at all in the code. How can I find what makes this class necessary? Even searching over the whole project doesn't give any results. It says that error is at PixmapTextureAtlas.java:16 (class source), but there is no code that uses that ImageElement class. Adding the library containing com.google.gwt.dom.client.ImageElement class helps, of course, but I'd like to figure out why this class in needed.
Here is the place in ant log that tells of the actual error:
Compiling 3 source files to /home/suseika/Projects/tendiwa/client/bin
/home/suseika/Projects/tendiwa/client/src/org/tendiwa/client/PixmapTextureAtlas.java:16: error: cannot access ImageElement
class file for com.google.gwt.dom.client.ImageElement not found
Here is the whole ant log:
/usr/lib/jvm/java-7-oracle/bin/java -Xmx128m -Xss2m -Dant.home=/opt/intellijidea/lib/ant -Dant.library.dir=/opt/intellijidea/lib/ant/lib -Dfile.encoding=UTF-8 -classpath /opt/intellijidea/lib/ant/lib/ant-apache-regexp.jar:/opt/intellijidea/lib/ant/lib/ant-swing.jar:/opt/intellijidea/lib/ant/lib/ant-apache-xalan2.jar:/opt/intellijidea/lib/ant/lib/ant-jdepend.jar:/opt/intellijidea/lib/ant/lib/ant-apache-resolver.jar:/opt/intellijidea/lib/ant/lib/ant-jsch.jar:/opt/intellijidea/lib/ant/lib/ant.jar:/opt/intellijidea/lib/ant/lib/ant-testutil.jar:/opt/intellijidea/lib/ant/lib/ant-launcher.jar:/opt/intellijidea/lib/ant/lib/ant-apache-bsf.jar:/opt/intellijidea/lib/ant/lib/ant-commons-logging.jar:/opt/intellijidea/lib/ant/lib/ant-netrexx.jar:/opt/intellijidea/lib/ant/lib/ant-junit.jar:/opt/intellijidea/lib/ant/lib/ant-commons-net.jar:/opt/intellijidea/lib/ant/lib/ant-apache-bcel.jar:/opt/intellijidea/lib/ant/lib/ant-antlr.jar:/opt/intellijidea/lib/ant/lib/ant-apache-log4j.jar:/opt/intellijidea/lib/ant/lib/ant-jai.jar:/opt/intellijidea/lib/ant/lib/ant-apache-oro.jar:/opt/intellijidea/lib/ant/lib/ant-jmf.jar:/opt/intellijidea/lib/ant/lib/ant-javamail.jar:/usr/lib/jvm/java-7-oracle/lib/tools.jar:/opt/intellijidea/lib/idea_rt.jar com.intellij.rt.ant.execution.AntMain2 -logger com.intellij.rt.ant.execution.IdeaAntLogger2 -inputhandler com.intellij.rt.ant.execution.IdeaInputHandler -buildfile /home/suseika/Projects/tendiwa/client/build.xml jar
build.xml
property
path
description
compile
ant
property
property
property
description
compile
mkdir
javac
jar
ant
property
description
_core_src_available
available
ontology
antcall
property
description
_core_src_available
available
_build_core
ant
property
property
compile
echo
/home/suseika/Projects/tendiwa/client
mkdir
javac
jar
jar
Building jar: /home/suseika/Projects/tendiwa/MainModule.jar
description
tempfile
mkdir
Created dir: /tmp/tendiwa373148820
unjar
Expanding: /home/suseika/Projects/tendiwa/MainModule.jar into /tmp/tendiwa373148820
Expanding: /home/suseika/Projects/tendiwa/tendiwa-backend.jar into /tmp/tendiwa373148820
Expanding: /home/suseika/Projects/tendiwa/tendiwa-ontology.jar into /tmp/tendiwa373148820
copy
Copying 1 file to /tmp/tendiwa373148820
java
Created item short_sword
Created item short_bow
Created item bucket
Created item boot
Created item steel_morningstar
Created item rifle_ammo
Created item handAxe
Created item iron_armor
Created item steel_mace
Created item jacket
Created item fedora
Created item wooden_arrow
Saving sources to /tmp/tendiwa373148820/ontology/src
tendiwa/resources/SoundTypes.java
tendiwa/resources/CharacterTypes.java
tendiwa/resources/ObjectTypes.java
tendiwa/resources/FloorTypes.java
tendiwa/resources/ItemTypes.java
tendiwa/resources/MaterialTypes.java
mkdir
mkdir
mkdir
Created dir: /tmp/tendiwa373148820/ontology/bin
javac
jar
Building jar: /home/suseika/Projects/tendiwa/tendiwa-ontology.jar
echo
Resources source code generated
ant
property
property
compile
echo
/home/suseika/Projects/tendiwa/client
mkdir
javac
jar
jar
jar
Building jar: /home/suseika/Projects/tendiwa/MainModule.jar
mkdir
javac
/home/suseika/Projects/tendiwa/client/build.xml:25: 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.GeneratedMethodAccessor4.invoke(Unknown Source)
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: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.Main.start(Main.java:180)
at org.apache.tools.ant.Main.main(Main.java:268)
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 com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
/home/suseika/Projects/tendiwa/client/build.xml (25:46)'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
Compiling 3 source files to /home/suseika/Projects/tendiwa/client/bin
/home/suseika/Projects/tendiwa/client/src/org/tendiwa/client/PixmapTextureAtlas.java:16: error: cannot access ImageElement
class file for com.google.gwt.dom.client.ImageElement not found
1 error
/home/suseika/Projects/tendiwa/client/build.xml:25: 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.GeneratedMethodAccessor4.invoke(Unknown Source)
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: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.Main.start(Main.java:180)
at org.apache.tools.ant.Main.main(Main.java:268)
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 com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
/home/suseika/Projects/tendiwa/client/build.xml:25: 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.GeneratedMethodAccessor4.invoke(Unknown Source)
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: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.Main.start(Main.java:180)
at org.apache.tools.ant.Main.main(Main.java:268)
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 com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
Ant build completed with 3 errors one warning in 4s at 10/30/13 3:09 AM
Here is a part of ant file where this error appears:
<path id="tendiwa.jars">
<fileset dir="../libs">
<include name="**/*.jar"/>
</fileset>
<pathelement path="../tendiwa-backend.jar"/>
<pathelement path="../tendiwa-ontology.jar"/>
<!--<fileset dir="/usr/share/java" includes="gwt*.jar"/>-->
</path>
<target name="compile">
<ant dir="../MainModule" target="jar"/>
<mkdir dir="bin"/>
<javac destdir="bin" failonerror="true">
<classpath>
<path refid="tendiwa.jars"/>
<!--temporary-->
<pathelement path="../tendiwa-ontology.jar"/>
<!--temporary-->
<pathelement path="../MainModule.jar"/>
<fileset dir="../libs" includes="**/*.jar"/>
</classpath>
<src>
<pathelement path="Desktop/src"/>
<pathelement path="src"/>
</src>
</javac>
</target>
A given library may have dependencies that it does not provide, so your code needs it indirectly. PixmapTextureAtlas.java:16 does reference this class, and you use PixmapTextureAtlas, therefore you indirectly need com.google.gwt.dom.client.ImageElement.
A tool like Maven can add dependencies/subdependencies and manage them easily.
I found out why that was happening. I accidentally added to classpath two different jars where are two different variants of class com.badlogic.gdx.graphics.Pixmap, one having dependency on GWT, and another being the one I needed. The problem was that I didn't know such situation is possible : )
I have my application entities in a separate project from my main servlet, and they aren't being DataNucleus enhanced.
Not sure if I'm just breaking the rules or what, but setting the ORM setting on the project doesn't enhance my .class files. The way my workspace is built is by compiling the projects, then running an ant script builds jar files and copies them into the lib directory of my servlet.
I suppose that if I must, I can add some java tasks to my ant scripts to enhance my .class files. If that's the case, an example of the task would be helpful.
I do want to keep my projects are they are, let me know what I need to do to maintain that.
This is my build.xml of the project containing my entities:
<project default="default">
<property name="appengine.sdk.dir" location="C:\superlongpathtomyeclipseplugins\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\appengine-java-sdk-1.6.5"/>
<import file="${appengine.sdk.dir}/config/user/ant-macros.xml"/>
<target name="default" depends="dist"/>
<target name="dist">
<enhance>
<classpath>
<pathelement path="${appengine.sdk.home}/lib/*"/>
<pathelement path="bin"/>
</classpath>
<fileset dir="bin" includes="**/*.class" />
</enhance>
<jar basedir="bin" destfile="dist\sessionexample.model.jar"/>
</target>
</project>
But now here is the error I'm getting:
java.lang.RuntimeException: Unexpected exception
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
at com.google.appengine.tools.enhancer.Enhance.(Enhance.java:71)
at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:74)
... 2 more
Caused by: java.lang.NoClassDefFoundError: com/google/appengine/api/datastore/Key
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getDeclaredMethods(Unknown Source)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getJavaBeanAccessorAnnotationsForClass(AbstractAnnotationReader.java:238)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:128)
at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:136)
at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2278)
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:385)
at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:743)
at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:545)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1252)
... 7 more
Caused by: java.lang.ClassNotFoundException: com.google.appengine.api.datastore.Key
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.google.appengine.tools.enhancer.EnhancerLoader.loadClass(EnhancerLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 18 more
Do I need to keep adding things to my <classpath> until it works?
The DataNucleus project defines many ways to run enhancement. It's for you to choose which one makes most sense to your environment and build system. Any other methods not defined on that page are not supported (by us)
Finally got an ant task to run:
<project default="default">
<property name="appengine.sdk.dir" location="c:\pathtoeclipse\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\appengine-java-sdk-1.6.5"/>
<import file="${appengine.sdk.dir}/config/user/ant-macros.xml"/>
<target name="default" depends="dist"/>
<target name="dist">
<enhance>
<classpath>
<pathelement path="${appengine.sdk.home}/lib/*"/>
<pathelement path="${appengine.sdk.home}/lib/user/*"/>
<pathelement path="${appengine.sdk.home}/lib/user/orm/*"/>
<pathelement path="bin"/>
</classpath>
<fileset dir="bin" includes="**/*.class" />
</enhance>
<jar basedir="bin" destfile="dist\sessionexample.model.jar"/>
</target>
</project>