Ant 无法找到外部定义的 taskdef 所需的类
我正在尝试使用 axis-java2wsdl ant 任务从我的 java 类之一创建 wsdl,但我无法获得正确的类路径。
我正在使用 Ubuntu 的 libaxis-java 软件包,它将 axis-ant.jar 安装在 $ANT_HOME/lib 中,将 axis.jar 安装在 /usr/share/java 中。 我的 build.xml 中有趣的部分如下所示:
<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 位于“库”定义的路径上
我知道这是一个类路径问题,因为我能够通过 DefaultAuthenticator 到达通过符号链接 axis.jar 未找到的其他类$ANT_HOME/lib。 如何让 taskdef 识别 /usr/share/lib 或项目的本地 lib 目录中的 jar 文件,而不将所有内容符号链接到 $ANT_HOME/lib 中?
编辑:
我终于能够用这一行成功生成 wsdl:
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 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.
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>
Running ant genwsdl
results in:
/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 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"
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?
EDIT:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
一般来说,这是有效的。 但你需要非常仔细地检查哪些类在哪里。
如果您的任务类可以加载到类加载器层次结构中较高的类加载器中(例如 CLASSPATH 或 ANT_HOME/lib),那么您的 classpathref 将被忽略。
请阅读常见问题解答条目了解更多详细信息。
注意:运行
ant -diagnostics
也有帮助。In general, this works. But you need to check very carefully which classes are where.
If your task class can be loaded in a classloader higher up in the classloader hierarchy (like CLASSPATH or ANT_HOME/lib) then your classpathref will simply get ignored.
Read the FAQ entry for more details.
Note: running
ant -diagnostics
can help too.Ant 添加库的机制是:
仅 。 手册没有提及任何有关使用system.library.dir属性的信息。 可能出于这个目的,它几乎被忽略了。
另外,在详细模式(和 -verbose )下运行 ant 来查看幕后正在做什么。
Ant mechanism for adding libraries is:
Only. The manual doesn't mention anything about using the system.library.dir property. Probably it pretty much ignored for this purpose.
Also, run ant in verbose mode ( and -verbose ) to see what is doing under the hood.
为什么不采用最简单的选项并在
中指定类路径?或者创建第二个
条目来子集library.dir
?乱搞
${ant.home}/lib
并不是一个好主意,而且几乎总是可以避免的。Why not just take the simplest option and specify the classpath in your
<taskdef>
?Or create a second
<classpath>
entry that subsetslibrary.dir
?Messing around with
${ant.home}/lib
is not such a good idea and can almost always be avoided.正如 matt b 所提到的,直接在 taskdef 任务中指定类路径对我来说是有效的。 对于我的项目,我发现将 taskdef 库包含在项目文件夹中并在 ant 构建文件中指定类路径非常有用,这样可以简单地在其他开发电脑上进行设置。 我使用以下taskdef:
请注意,这可能不适用于 1.7.0 之前的 ant 版本。
It works for me to specify the classpath directly in the taskdef task, as menstioned by matt b. For my project I find it useful to include the taskdef library in the project folder and specify the classpath in the ant build file, to simply setup on other development pcs. I use the following taskdef:
Note that this might not work for versions of ant earlier than 1.7.0.
使用这里的答案和所有部分信息,我想出了一个解决方案。 我将 ant 文件所需的 jar 添加到项目中的 lib 文件夹中(特别是 mysql jdbc 驱动程序)。 然后我在 ant 中运行一个设置任务,将其复制到用户的主 .ant/lib 文件夹,然后 ant 失败并显示一条重新启动消息。 对于一个用户来说,它只失败一次,然后每次都可以工作。 如果您将 jar 更新到新版本,这可能会很棘手...
这是 ant build.xml:
希望这有帮助
Using the answers from here and all the partial information, I came up with a solution. I added the jar the ant file needed to a lib folder in the project (specifically mysql jdbc drivers). Then I run a setup task in ant that copies to the user's home .ant/lib folder, and then fails ant with a message to restart. It only fails once for a user, and then works every time. It might be tricky if you update the jar to a new version...
Here's the ant build.xml:
Hope this helps
当我将 *.jar 复制到 {ant.home}/libs 时,我遇到了同样的问题,然后我使用 -lib 找到 *.jar,它运行正常! 我认为是新罐子无法加载,那我测试一下!
I met the same problem when I copy a *.jar to the {ant.home}/libs, then i user the -lib to locate the *.jar, it's runs ok! I consider it's the new jars can't be loaded, then i'll test it!