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

查看:46
本文介绍了Ant 在构建时找不到 ant 类 (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-code-generation 目标中,并在它调用简单的 ant 复制方法时发生.它找不到的类(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.

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

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