问题
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.
回答1:
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.
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/14523042/ant-cant-find-an-ant-class-dateutils-while-building