构建时,蚂蚁找不到蚂蚁类(DateUtils) [英] Ant can't find an ant class (DateUtils) while building

查看:95
本文介绍了构建时,蚂蚁找不到蚂蚁类(DateUtils)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过ant构建一个项目.它可以通过ant在本机上正常构建,但是在我们的构建机上,我得到了:

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)

这在jaxb代码生成目标中发生,并且在它调用简单的ant copy方法时发生.它找不到的类(DateUtils)在ant.jar本身之内,而且我不知道如何获取该类以为该目标加载ant.jar(我以为已经有可用的ant.jar了.因为它在ant中运行).我知道这是一个类路径问题,但无法找出解决方法.

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.

这是直到失败的副本的ant构建文件的一部分:

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>

同样,这在我的本地计算机上也可以正常工作.我的本地计算机和构建计算机都运行Java 1.6和Ant 1.7.1,并且都运行linux(我的计算机是Linux Mint,构建计算机是Ubuntu).

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).

更新:数据点:我创建了一个仅复制文件的新build.xml.它使用了相同的ant方法,单独运行时效果很好.

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.

推荐答案

我在看似相关的构建问题中也遇到了同样的问题(至少是相同的错误). 对我有用的解决方案只是设置ANT_HOME环境变量. 这似乎没有必要,因为ant位于PATH中,所以我希望它会找到所需的所有内容,但似乎没有.当我将ANT_HOME设置为正确的路径时,便会构建相同的项目.

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.

这篇关于构建时,蚂蚁找不到蚂蚁类(DateUtils)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆