Ant 找不到外部定义的 taskdef 所需的类 [英] Ant cannot find a class needed by an externally defined taskdef

查看:28
本文介绍了Ant 找不到外部定义的 taskdef 所需的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 axis-java2wsdl ant 任务从我的一个 java 类创建 wsdl,但我无法获得正确的类路径.

I am trying to use the axis-java2wsdl ant task to create a wsdl from one of my java classes, but I cannot get the classpath correct.

我正在使用 Ubuntu 的 libaxis-java 包,它在 $ANT_HOME/lib 中安装 axis-ant.jar,在/usr/share/java 中安装 axis.jar.我的 build.xml 中有趣的部分如下所示:

I am using Ubuntu's libaxis-java package which installs axis-ant.jar in $ANT_HOME/lib and axis.jar in /usr/share/java. The interesting parts of my build.xml look like this:

<property name="library.dir" value="lib"/>
<property name="system.library.dir" value="/usr/share/java"/>
<path id="libraries">
    <fileset dir="${library.dir}">
        <include name="*.jar"/>
    </fileset>
    <fileset dir="${system.library.dir}">
        <include name="*.jar"/>
    </fileset>
</path>

<target name="genwsdl" depends="compile">
    <taskdef resource="axis-tasks.properties" classpathref="libraries"/>
    <axis-java2wsdl>
            details omitted
    </axis-java2wsdl>
</target>

运行 ant genwsdl 结果:

/build.xml:50: taskdef A class needed by class
org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask
cannot be found: org/apache/axis/utils/DefaultAuthenticator

Ant 能够找到axis-java2wsdl 任务的定义,因为axis-ant.jar 在$ANT_HOME/lib 中,但是它在axis.jar 中找不到类,即使那个jar 在定义的路径上图书馆"

Ant is able to find the definition of the axis-java2wsdl task, because axis-ant.jar is in $ANT_HOME/lib, but it cannot find classes in axis.jar, even though that jar is on the path defined by "libraries"

我知道这是一个类路径问题,因为通过将axis.jar 符号链接到$ANT_HOME/lib 中,我能够通过DefaultAuthenticator 到其他未找到的类.如何让 taskdef 识别/usr/share/lib 或我项目的本地 lib 目录中的 jar 文件,而无需将所有内容符号链接到 $ANT_HOME/lib 中?

I know it's a classpath issue because I was able to get past DefaultAuthenticator to other class's not found by symlinking axis.jar into $ANT_HOME/lib. How can I get the taskdef to recognize jar files in /usr/share/lib or my project's local lib directory without symlinking everything into $ANT_HOME/lib?

我终于能够用这一行成功生成 wsdl:

I was finally able to successfully generate the wsdl with this line:

ant -lib /usr/share/java/axis.jar -lib /usr/share/java/jaxrpc.jar -lib /usr/share/java/wsdl4j.jar -lib /usr/share/java/commons-logging.jar -lib /usr/share/java/commons-discovery.jar -lib build genwsdl

如果有人能告诉我无法在 build.xml 中定义这些库,我做错了什么,我将不胜感激

I would still very much appreciate if somebody could tell me what I'm doing wrong in not being able to define those libraries in build.xml

推荐答案

一般来说,这是有效的.但是你需要非常仔细地检查哪些类在哪里.

In general, this works. But you need to check very carefully which classes are where.

如果您的任务类可以在类加载器层次结构中更高的类加载器中加载(如 CLASSPATH 或 ANT_HOME/lib),那么您的 classpathref 将被忽略.

阅读常见问题解答了解更多详情.

Ant 的类加载器实现使用 Java 的委托模型

Ant's class loader implementation uses Java's delegation model

ClassLoader 类使用委托模型来搜索类和资源.ClassLoader 的每个实例都有一个关联的父类加载器.当调用查找类或资源时,ClassLoader 实例将在尝试查找类或资源本身之前将类或资源的搜索委托给其父类加载器.虚拟机的内置类加载器,称为引导类加载器,它本身没有父级,但可以作为 ClassLoader 实例的父级.

The ClassLoader class uses a delegation model to search for classes and resources. Each instance of ClassLoader has an associated parent class loader. When called upon to find a class or resource, a ClassLoader instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself. The virtual machine's built-in class loader, called the bootstrap class loader, does not itself have a parent but may serve as the parent of a ClassLoader instance.

注意:运行 ant -diagnostics 也有帮助.

这篇关于Ant 找不到外部定义的 taskdef 所需的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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