I got this errors when I'm trying to compile a program that use classes and interfaces that are placed in packages.
C:\Users\Florin\Documents\Anul3\PD\Teme\Program\ConvertorValutar>MyAnt.bat
C:\Users\Florin\Documents\Anul3\PD\Teme\Program\ConvertorValutar>set ANT_HOME=c
\Users\Florin\Documents\Anul3\PD\Teme\apache-ant-1.8.1\
C:\Users\Florin\Documents\Anul3\PD\Teme\Program\ConvertorValutar>set JAVA_HOME=
:\Program Files\Java\jdk1.7.0_17
C:\Users\Florin\Documents\Anul3\PD\Teme\Program\ConvertorValutar>c:\Users\Flori
\Documents\Anul3\PD\Teme\apache-ant-1.8.1\\bin\ant.bat
Buildfile: C:\Users\Florin\Documents\Anul3\PD\Teme\Program\ConvertorValutar\bui
d.xml
init:
[mkdir] Created dir: C:\Users\Florin\Documents\Anul3\PD\Teme\Program\Conver
orValutar\build
[mkdir] Created dir: C:\Users\Florin\Documents\Anul3\PD\Teme\Program\Conver
orValutar\build\main
Compile:
[javac] Compiling 6 source files to C:\Users\Florin\Documents\Anul3\PD\Teme
Program\ConvertorValutar\build
[javac] Note: C:\Users\Florin\Documents\Anul3\PD\Teme\Program\ConvertorValu
ar\src\main\server\CursValutar.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
Run:
[java] java.lang.NoClassDefFoundError: server/CursValutarServer (wrong nam
: main/server/CursValutarServer)
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[java] at java.security.SecureClassLoader.defineClass(SecureClassLoade
.java:142)
[java] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[java] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[java] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.
ava:482)
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Even if says BUILD SUCCESSFUL i got error when I'm trying to run a compiled class:
Exception in thread "main" java.lang.NoClassDefFoundError: MyMServer (wrong nam
: main/server/impl/MyMServer)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
The content of build.xml is:
<project name="Socket" default="Run" basedir=".">
<!-- set global properties for this build.dir -->
<property name="main.class" value="server.CursValutarServer"/>
<property name="build.dir" location="build"/>
<property name="src.dir" location="src" />
<property name="host" value="localhost"/>
<property name="port" value="7999"/>
<path id="myclasspath">
<pathelement path="${build.dir}/main"/>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build.dir directory structure used by compile -->
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dir}/main" />
</target>
<target name="Compile" depends="init" description="compile the source " >
<javac srcdir="${src.dir}" destdir="${build.dir}"
classpathref="myclasspath" includeantruntime="false"/>
</target>
<target name="Run" depends="Compile">
<java classname="${main.class}" classpathref="myclasspath" fork="true"/>
</target>
<target name="Client">
<java classname="client.CursValutarClient" classpathref="myclasspath" fork="true">
<arg line="${host} ${port}" />
</java>
</target>
</project>
You're compiling the classes into the directory "build":
<javac srcdir="${src.dir}" destdir="${build.dir}" ..
But the classpath is set to "build/main":
<path id="myclasspath">
<pathelement path="${build.dir}/main"/>
</path>
Related
I'm trying to compile and run a JavaFX project using ant. Compilation using ant is OK, however, when I try to use ant run and launch the application, i get this error:
run:
[java] Exception in Application start method
[java] java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
[java] at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
[java] Caused by: java.lang.RuntimeException: Exception in Application start method
[java] at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
[java] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
[java] at java.lang.Thread.run(Thread.java:748)
[java] Caused by: java.lang.IllegalStateException: Location is not set.
[java] at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
[java] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
[java] at main.Main.start(Unknown Source)
[java] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
[java] at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
[java] at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
[java] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
[java] at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
[java] at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
[java] ... 1 more
[java] Exception running application main.Main
[java] Java Result: 1
From what I've found online, this error occurs, when the project's .fxml file can't be found.
This only occurs when I try to use ant to run the program. When I run it using intelliJ IDE everything works just fine. I've even reproduced this error when running the program using IDE by giving it wrong .fxml resource url. So I guess that ant just can't find the fxml file, hovewer I am lost in this regard and dont know how to make my build.xml find the .fxml.
This is my build.xml file:
<project name="ija-app" basedir=".">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="jar.dir" value="dest"/>
<property name="lib.dir" value="lib"/>
<property name="main-class" value="main.Main"/>
<path id="classpath">
<pathelement location="${lib.dir}/jackson-annotations-2.9.0.jar"/>
<pathelement location="${lib.dir}/jackson-core-2.9.9.jar"/>
<pathelement location="${lib.dir}/jackson-databind-2.9.9.jar"/>
<pathelement location="${lib.dir}/jackson-dataformat-yaml-2.9.9.jar"/>
<pathelement location="${lib.dir}/snakeyaml-1.23.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}/*"/>
<delete file="${lib.dir}/*.jar"/>
</target>
<target name="compile" depends="clean">
<exec executable="/bin/bash">
<arg value="./lib/get-libs.sh"/>
</exec>
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath>
<path refid="classpath"/>
</classpath>
</javac>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar"/>
</jar>
</target>
<target name="docs" depends="compile">
<javadoc soudepath="${src.dir}" destdir="${doc.dir}">
<classpath>
<path refid="classpath"/>
</classpath>
</javadoc>
</target>
<target name="run">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
</project>
Thanks for any tips on how to get it running.
I have a Java program using number of external libraries. The program compiles and runs in the Eclipse IDE without any issues. However, when using an ant build.xml, compilation works fine, but throws the following exception when during run time.
run:
[java] Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/jna/Library
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[java] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[java] at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
[java] at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] at org.freedesktop.gstreamer.Gst.getVersion(Unknown Source)
[java] at org.freedesktop.gstreamer.Gst.init(Unknown Source)
[java] at org.freedesktop.gstreamer.Gst.init(Unknown Source)
[java] at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
[java] at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
[java] at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
[java] at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
[java] at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
[java] at java.awt.Component.processMouseEvent(Component.java:6539)
[java] at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
[java] at java.awt.Component.processEvent(Component.java:6304)
[java] at java.awt.Container.processEvent(Container.java:2239)
[java] at java.awt.Component.dispatchEventImpl(Component.java:4889)
[java] at java.awt.Container.dispatchEventImpl(Container.java:2297)
[java] at java.awt.Component.dispatchEvent(Component.java:4711)
[java] at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
[java] at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
[java] at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
[java] at java.awt.Container.dispatchEventImpl(Container.java:2283)
[java] at java.awt.Window.dispatchEventImpl(Window.java:2746)
[java] at java.awt.Component.dispatchEvent(Component.java:4711)
[java] at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
[java] at java.awt.EventQueue.access$500(EventQueue.java:97)
[java] at java.awt.EventQueue$3.run(EventQueue.java:709)
[java] at java.awt.EventQueue$3.run(EventQueue.java:703)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
[java] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
[java] at java.awt.EventQueue$4.run(EventQueue.java:733)
[java] at java.awt.EventQueue$4.run(EventQueue.java:731)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
[java] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
[java] at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
[java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
[java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
[java] Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 52 more
The build script I'm using is given below.
<property name="src.dir" value="src/org"/>
<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="Libs" />
<property name="main-class" value="org.ai.receiver.DashboardLauncher"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}/ai/receiver:${src.dir}/freedesktop/gstreamer" destdir="${classes.dir}" includeantruntime="false">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</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 jar="${jar.dir}/${ant.project.name}.jar" fork="true">
<classpath>
<pathelement location="Libs/jna.jar:Libs/jna-platform.jar:Libs/swt.jar"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
The required external libraries "jna.jar", "jna-platform.jar" and "swt.jar" files are located in the "Lib" directory.
It seems to me that these external libraries are not properly loading during the run time, yet they are properly linked during the compile time. A similar issue is discussed in this github issue tracker, but the discussion doesn't provide a proper solution.
Could you please help me to fix this issue?
Thank you.
This issue was resolved by changing the target for .jar as follows:
<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>
<zipgroupfileset dir="Libs" includes="*.jar" />
</jar>
</target>
Ok, so I asked this question yesterday, and I still haven't found my solution, but I luckily I have enabled more logging and I am receiving this error message:
C:\....\nbproject\build-impl.xml:1039: The following error occurred while executing this line:
C:\....\nbproject\build-impl.xml:804: Java returned: 1
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor245.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor245.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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.MacroInstance.execute(MacroInstance.java:396)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor245.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:286)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:555)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
BUILD FAILED (total time: 6 minutes 8 seconds)
Could not load class (org.apache.tools.ant.taskdefs.repository.MavenRepository) for type mavenrepository
Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
Could not load a dependent class (javax/media/jai/PlanarImage) for type image
Could not load class (org.apache.tools.ant.taskdefs.repository.MavenRepository) for type mavenrepository
Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
Could not load a dependent class (javax/media/jai/PlanarImage) for type image
I am using NetBeans 8.1 with only JDK 8 (both 32bit). I am also using Windows 8. I have performed a clean on the build-impl.xml from within NetBeans and I am still seeing this issue. Is it related to Ant somehow? I don't even really know what Ant is or does.
Here is the output for line 1039:
<j2seproject1:java>
<customize>
<arg line="${application.args}"/>
</customize>
</j2seproject1:java>
Here is the output for line 804
<java classname="#{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
<jvmarg line="${run.jvmargs}"/>
<jvmarg line="${run.jvmargs.ide}"/>
<classpath>
<path path="#{classpath}"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<customize/>
</java>
I have had the same problem and I have created a new glassfihs server and then it has worked...
I'm trying to use the schemagen ant task from JAXB-RI 2.2.7, but I keep getting "BUILD FAILED .... Error starting ap" on the schemagen task in build.xml. The relevant stanzas are as follows:
<taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask">
<classpath refid="compile.classpath"/>
</taskdef>
<target name="schemas" description="Compile all Java source files">
<mkdir dir="${schemas.dir}" />
<schemagen destdir="${schemas.dir}">
<src path="${src.dir}"/>
<classpath refid="compile.classpath" />
</schemagen>
</target>
With -verbose, I get the stack trace below. I've tried googling for the details of the ClassCastException but not found anything. Any suggestions?
Thanks, Adam
BUILD FAILED
/home/adam/sandboxes/adam/sensei/code/trunk/repository/build.xml:99: Error starting ap
at com.sun.tools.jxc.ApBasedTask$InternalApAdapter.execute(ApBasedTask.java:131)
at com.sun.tools.jxc.ApBasedTask.compile(ApBasedTask.java:170)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:930)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
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:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
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.RuntimeException: java.lang.AssertionError: java.lang.ClassCastException: com.sun.tools.javac.api.JavacTrees cannot be cast to com.sun.source.util.Trees
at com.sun.tools.javac.main.Main.compile(Main.java:469)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at com.sun.tools.jxc.ApBasedTask$InternalApAdapter.execute(ApBasedTask.java:127)
... 18 more
Caused by: java.lang.AssertionError: java.lang.ClassCastException: com.sun.tools.javac.api.JavacTrees cannot be cast to com.sun.source.util.Trees
at com.sun.source.util.Trees.getJavacTrees(Trees.java:84)
at com.sun.source.util.Trees.instance(Trees.java:73)
at com.sun.tools.jxc.model.nav.ApNavigator.getClassLocation(ApNavigator.java:410)
at com.sun.tools.jxc.model.nav.ApNavigator.getClassLocation(ApNavigator.java:83)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getLocation(ClassInfoImpl.java:1284)
at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.convert(IllegalAnnotationException.java:122)
at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.build(IllegalAnnotationException.java:106)
at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.<init>(IllegalAnnotationException.java:70)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.<init>(ClassInfoImpl.java:211)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.createClassInfo(ModelBuilder.java:399)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:257)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:227)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:375)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:390)
at com.sun.tools.jxc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.java:95)
at com.sun.tools.jxc.ap.SchemaGenerator.process(SchemaGenerator.java:110)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
... 20 more
Caused by: java.lang.ClassCastException: com.sun.tools.javac.api.JavacTrees cannot be cast to com.sun.source.util.Trees
at com.sun.source.util.Trees.getJavacTrees(Trees.java:82)
... 43 more
Same problem here. From the stack trace I would say it's some error in JAXB annotation, but while xjc tries to handle that exception it fails with another one and there's no way of knowing in which class and property the problem is.
I am running JUnit tests using Ant on the command line on Windows XP.
On some runs, midway through running all of the tests, I will get a BUILD FAILED message pointing at a specific test class, but all of the tests in that class are reported as having passed both in the console output and in the XML file.
The class contains no non-determinism and should not have any side-effects. There is no reason for it to be running out of memory either.
What could cause these strange build failures?
Update:
I doubt this will be helpful, but here is the end of the run when it fails (modified directory and package names for anonymity):
C:\proj\er20\rr> ant clean build test
<snip/>
[junit] Running com.example.PathUTest
[junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 7.5 sec
BUILD FAILED
C:\proj\er20\common\build.xml:385: The following error occurred while executing this line:
C:\proj\er20\rr\build.xml:58: Test com.example.PathUTest failed
Update 2:
I have finally managed to get the failure to happen with -verbose enabled. Here is the stacktrace (copied by hand):
BUILD FAILED
C:\proj\er20\common\build.xml:385: The following error occurred while executing this line:
C:\proj\er20\rr\build.xml:58: Test com.example.PathUTest failed
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:541)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:418)
at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
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:105)
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:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: C:\proj\er20\rr\build.xml:58: Test com.example.PathUTest failed
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.actOnTestResult(JUnitTask.java:1712)
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:820)
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.executeOrQueue(JUnitTask.java:1657)
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:764)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
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:105)
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:1329)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
... 17 more
--- Nested Exception ---
C:\proj\er20\rr\build.xml:58 Test com.example.PathUTest failed
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.actOnTestResult(JUnitTask.java:1712)
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:820)
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.executeOrQueue(JUnitTask.java:1657)
at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:764)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
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:105)
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.perform(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
at org.apache.tools.ant.tskdefs.CallTarget.execute(CallTarget.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor4.invoke(Source Unknown)
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:105)
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:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 1 minute 27 seconds
And here is the relevant Ant target:
<target name="test">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="../buildsupport/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- line 58 is the next line -->
<junit printsummary="yes" fork="yes" haltonfailure="yes" dir="${test-dir}" showoutput="yes">
<jvmarg value="-Xmx10200M"/>
<jvmarg value="-Xms600M"/>
<jvmarg value="-server"/>
<jvmarg value="-Dlog4j.configuration=file:log4j.xml"/>
<jvmarg value="-XX:CompileCommand=exclude,com.example.GtaCore,expandLabel"/>
<env key="LD_LIBRARY_PATH" path="${env.LD_LIBRARY_PATH}:${test-dir}/native_lib"/>
<jvmarg value="-Djava.library.path=./native_lib"/>
<formatter type="xml"/>
<classpath>
<!-- classpath items -->
</classpath>
<batchtest>
<fileset includes="**/*Test.class" excludes="**/*$$*.class"/>
</batchtest>
</junit>
<junitreport>
<!-- config -->
</junitreport>
<echo> finished suite</echo>
</target>
Probable Cause and Solution
We discovered that deep down within code that we were calling, an error debugging GUI was being displayed which ran in another thread. Since disabling the display of this GUI, we have not seen this issue again.
Maybe in rr\build.xml (you have 2 build files) at line 58 there is
<fail message="Test com.example.PathUTest failed"/>