I'm trying to get a project to build via ant. It builds just fine via ant on my local machine, but on our build machine I get :
java.lang.NoClassDefFoundError: org/apache/tools/ant/util/DateUtils
at org.apache.tools.ant.DefaultLogger.formatTime(DefaultLogger.java:323)
at org.apache.tools.ant.DefaultLogger.buildFinished(DefaultLogger.java:170)
at org.apache.tools.ant.Project.fireBuildFinished(Project.java:
at org.apache.tools.ant.Main.runBuild(Main.java:778)
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.lang.ClassNotFoundException: org.apache.tools.ant.util.DateUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
This happens within the jaxb-code-generation target and happens when it calls a simple ant copy method. The class it can't find (DateUtils) is within the ant.jar itself and I can't figure out how to get it to load the ant.jar for this target (which I would have thought already had the ant.jar available since it's running within ant). I know this is a classpath problem but cannot figure out how to fix it.
Here's the part of the ant build file up to the copy that fails:
<target name="jaxb-code-generation" depends="xjc-typedef-target,-do-init,-init-macrodef-javac">
<mkdir dir="${build.generated.sources.dir}/jaxb" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="build/generated/jaxbCache" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="build/generated/jaxbCache/Listing"/>
<xjc package="Listing" destdir="build/generated/jaxbCache/Listing" catalog="catalog.xml">
<classpath>
<pathelement location="${src.dir}"/>
<pathelement path="${jaxbwiz.xjcrun.classpath}"/>
</classpath>
<arg value="-xmlschema"/>
<schema file="xml-resources/jaxb/Listing/Listing.xsd"/>
<depends file="xml-resources/jaxb/Listing/Listing.xsd"/>
<produces dir="build/generated/jaxbCache/Listing"/>
</xjc>
<copy todir="${build.generated.sources.dir}/jaxb">
<fileset dir="build/generated/jaxbCache/Listing"/>
</copy>
Again, this works fine on my local machine. Both my local machine and the build machine are running Java 1.6 and Ant 1.7.1 and both are linux (mine is Linux Mint and the build machine is Ubuntu).
UPDATE: Data point: I created a new build.xml that just copies a file, that's it. it used the same ant method and that worked fine when run solo.
I had this same problem (same error, at least) in what seems like a related build problem.
The solution that worked for me was simply to set ANT_HOME environment variable.
This seems unnecessary, because ant is in the PATH, so I'd expect it would have found everything it needed, but it appeared to not. When I set ANT_HOME to the correct path, the same project then built.
Sometimes I use this:
jarfinder
You can check org/apache/tools/ant/util/DateUtils
I am not sure which you miss, but maybe helps to guess.
Run xjc native with something like this:
<target name="xjc">
<exec executable="xjc">
<arg value="-d"/>
<arg value="src"/>
<arg value="-p"/>
<arg value="bla.bla.bla"/>
<arg value="${xjc.in.dir}/bla.xsd"/>
</exec>
</target>
Works flawless for me.
found here
Related
I'm using ant scripts for initializing my exist-db.
But, I have this script below (dummy version) which is working in my local platform and not on my procution one. As I'm not the one who handle the configuration of this database, I don't know where to look in the conf to fix this.
Here is the script (which is just trying to add a new user) :
<project basedir="." default="default" name="ANTProject">
<property file="load.properties"/>
<path id="classpath.core">
<fileset dir="${path}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${path}\exist.jar"/>
<pathelement path="${path}\exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<target name="default">
<echo message="Création du compte ${login}"/>
<xdb:adduser xmlns:xdb="http://exist-db.org/ant"
uri="xmldb:exist://${exist.uri}/exist/xmlrpc/db"
name="${login}" secret="${password}" primaryGroup="${user.group}" user="${root.login}"
password="${root.password}"/>
</target>
</project>
I get this error message :
XMLDB exception caught: No such handler: Default.setUser
I get the same thing if I use xdb:users task, but the xdb:store is working well... I'm running exist 2.1, in both my local and production plateform, and as already told, same scripts working well on local one...
I guess, it's something about the exist configuration, but I didn't find anything on enabling this tasks in the documentation.
If someone could help...
Ok, I got it.
Just for completeness, It was an issue on jar librairies. It seems I used ones which support xdb:store, but not others tasks (didn't find any release version of this)...
This ant depandancies is quite tricky and It's hard to know what your jars offer...
I'm running an ant build file that creates a Jar. The task looks like this:
<target name="generator-app" depends="clean,compile">
<jar jarfile="${gen.App}">
<manifest>
...
</manifest>
<fileset dir="${classes}">
<include name="com/mypackage/**" />
</fileset>
<zipfileset dir="${jars}" />
</jar>
</target>
The build file runs and creates the file as expected when I run it on Linux, but fails with this error on any other platform:
BUILD FAILED /home/user/build.xml:287: the archive doesn't exist
I tried using destfile instead of jarfile, but the same result occurs. The archive does not exist indeed, but the purpose of the task is to create it.
Is there any limitation on certain platforms or any way to correct this?
Forward slashes don't seem very windowy to me :) Maybe you should convert your slashes based on your os? Do you pass this path somewhere?
I found the problem. I tried using a newer version of ant, and now the error indicates exactly what is missing (a jar to be packaged in the jar to be created).
I'm developing an ant script which is calling another ant script using the <ant> task. This ant script is an installer a Java product and is to be used by our customers, who will have ant installed separately.
The script being called uses the antlr task <antlr:ant-antlr3>. To do this I must place the ant-antlr3.jar file in the ant lib directory, as well as adding antlr-3.2.jar to the classpath.
But I don't want to have this dependency of having ant-antl3.jar file in the client's own installed version of ant.
Is there a way of providing the equivalent to ant's command-line '-lib' option to specify other paths for jars to be added to antlib using the <ant> task itself?
I've taken a look at the online docs and there doesn't seem to be a way.
Thanks
I believe the accepted way to do this is to manually set up your classpath in the build file rather than implicitly including it via the global ant lib directory. i.e.
<path id="master-classpath">
<fileset dir="${lib}" />
<fileset file="${findbugs-base}/lib/annotations.jar" />
<pathelement location="${build-classes}" />
</path>
You can then use this path element in any task that can accept classpath args such as javac
<javac
destdir="${out}"
source="1.5"
target="1.5"
debug="true">
<src path="${src}" />
<classpath refid="master-classpath" />
</javac>
This way, the global ant set up isn't a dependency, and you can specify any files you might need for any build, as specifically as you need to (down to a given call or target).
Obviously, this is all to be carried out in the build file you're calling from the clients' build file. This way, when you call out to yours, the classpath will be set up exactly as you desire.
Another far less idiomatic possibility would be to literally shell out with the Exec Task and call ant that way. Obviously, with the provision of the Ant task, the developers of ant don't recommend you doing that. It is an option, nonetheless.
Tim's answer gives most of the story, but in order to run Ant and set JVM options, you'd need to invoke it via the java task.
There is an example of running this way in the Ant docs, here slightly modified to include -lib:
<java
classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="${sub.builddir}"
timeout="4000000"
taskname="startAnt"
>
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
<arg value="-lib"/>
<arg value="${path.to.your.antlr.jar}"/>
<arg value="-buildfile"/>
<arg file="${sub.buildfile}"/>
<arg value="${sub.target}"/>
</java>
<target name="results">
<echo message="Calculating QI" />
<java jar="jmt.jar" fork="true" failonerror="true" maxmemory="1024m" classpath="jmt/jmt">
<arg value="-name:KIS"/>
<arg value="-results:CONSOLE"/>
<arg value="../allJavas.jar"/>
</java>
</target>
i want from folder tmp run jar file in folder jmt/jmt. It must be run inside jmt/jmt folder becouse of dependencies files.
i can run it like <java jar="jmt/jmt/jmt.jar" but then dependencies files are not ok. I try to use classpath but not working. What i am doing wrong?
Use the dir="jmt/jmt" attribute to specify the folder to launch the java process in, and use jar="jmt/jmt/jmt.jar" to specify the jar. You probably don't need to classpath attribute at all.
See http://ant.apache.org/manual/Tasks/java.html
The java ant task takes an option parameter dir="jmt/jmt" that will tell the forked VM where to execute.
I am using JAXB on a project. the attraction of JAXB is that it is bundled with the JDK, I have been to use xjc.exe on the command line to generate the .java files from a schema. I can't seem to find the JAXB ant task, sure there is a download at http://jaxb.java.net however i want to use the JAXB that is bundled into the JDK is there some way to call JAXB from ant what class does the xjc.exe call on?
<target name="generate-jaxb-code">
<java classname="com.sun.tools.internal.xjc.XJCFacade">
<arg value="-p" />
<arg value="com.example"/>
<arg value="xsd/sample.xsd" />
</java>
</target>
Just went hunting in the tools.jar and found the XJCFacade.class in com.sun.tools.internal tested the above code it works it produces the output as xjc.exe It seems that XJC.exe calls this code com.sun.tools.internal.xjc.XJCFacade
One of my key requirements was that the ant file had work within eclipse without having to include a path name to the JDK that way the file would be portable across operating systems. I am assuming that tools.jar is included on the classpath via the installed JRE preferences options.
Here is a helpful link:
https://jaxb.java.net/nonav/2.0.2/docs/xjcTask.html
Java SE 6 does not ship the Ant task (see 7.1.3):
https://jaxb.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.html
Essentially they do the following:
<target name="xjc" description="....">
<exec executable="${jdk.dir}/bin/xjc.exe">
<arg value="-d"/>
<arg value="${src.dir}"/>
<arg value="-p"/>
<arg value="com.mydomain.jaxb"/>
<arg value="${etc.dir}/myschema.xsd"/>
</exec>
</target>