Ant 无法找到外部定义的 taskdef 所需的类

发布于 2024-07-13 12:49:58 字数 1646 浏览 9 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

二手情话 2024-07-20 12:49:58

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

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

请阅读常见问题解答条目了解更多详细信息。

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

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

注意:运行 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.

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

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.

Note: running ant -diagnostics can help too.

晨敛清荷 2024-07-20 12:49:58

Ant 添加库的机制是:

  • 通过命令行参数 -lib
  • 添加到 ${user.home}/.ant/lib
  • 添加到 ${ant.home}/lib

仅 。 手册没有提及任何有关使用system.library.dir属性的信息。 可能出于这个目的,它几乎被忽略了。

另外,在详细模式(和 -verbose )下运行 ant 来查看幕后正在做什么。

Ant mechanism for adding libraries is:

  • via command line argument -lib
  • adding to ${user.home}/.ant/lib
  • adding to ${ant.home}/lib

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.

眼前雾蒙蒙 2024-07-20 12:49:58

为什么不采用最简单的选项并在 中指定类路径?

<taskdef resource="axis-tasks.properties">
    <classpath>
        <fileset file="/path/to/axis/jars"/>
    </classpath>
</taskdef>

或者创建第二个条目来子集library.dir

<path id="axis-tools-classpath">
    <fileset dir="/path/to/axis/home">
        <include name="*.jar"/>
    </fileset>
    <path refid="library.dir"/>
</path>

乱搞 ${ant.home}/lib 并不是一个好主意,而且几乎总是可以避免的。

Why not just take the simplest option and specify the classpath in your <taskdef>?

<taskdef resource="axis-tasks.properties">
    <classpath>
        <fileset file="/path/to/axis/jars"/>
    </classpath>
</taskdef>

Or create a second <classpath> entry that subsets library.dir?

<path id="axis-tools-classpath">
    <fileset dir="/path/to/axis/home">
        <include name="*.jar"/>
    </fileset>
    <path refid="library.dir"/>
</path>

Messing around with ${ant.home}/lib is not such a good idea and can almost always be avoided.

维持三分热 2024-07-20 12:49:58

正如 matt b 所提到的,直接在 taskdef 任务中指定类路径对我来说是有效的。 对于我的项目,我发现将 taskdef 库包含在项目文件夹中并在 ant 构建文件中指定类路径非常有用,这样可以简单地在其他开发电脑上进行设置。 我使用以下taskdef:

<taskdef resource="antenna.properties" classpath="${myprojectroot}/lib/antenna-bin-1.2.1-beta.jar"/>

请注意,这可能不适用于 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:

<taskdef resource="antenna.properties" classpath="${myprojectroot}/lib/antenna-bin-1.2.1-beta.jar"/>

Note that this might not work for versions of ant earlier than 1.7.0.

薄暮涼年 2024-07-20 12:49:58

使用这里的答案和所有部分信息,我想出了一个解决方案。 我将 ant 文件所需的 jar 添加到项目中的 lib 文件夹中(特别是 mysql jdbc 驱动程序)。 然后我在 ant 中运行一个设置任务,将其复制到用户的主 .ant/lib 文件夹,然后 ant 失败并显示一条重新启动消息。 对于一个用户来说,它只失败一次,然后每次都可以工作。 如果您将 jar 更新到新版本,这可能会很棘手...

这是 ant build.xml:

<project name="data_source" default="build">

  <!-- BUILD PROPERTIES -->
  <property file="build.properties"/>

  <!-- SQL Server Properties -->
  <property name="sql.driver" value="org.gjt.mm.mysql.Driver"/>
  <property name="sql.url" value="jdbc:mysql://127.0.0.1/datastore"/>
  <property name="sql.user" value="user"/>
  <property name="sql.pass" value="password"/>

  <!-- FILE LOCATIONS  -->
  <property name="sql.dir" location="sql"/>

  <!-- INITIALIZE PROJECT -->
  <target name="init" description="Initialize the project">
      <available property="no.ant.lib.dir" file="${user.home}/.ant/lib/" type="dir" />
  </target>

  <!-- SETUP MYSQL -->
  <target name="setup_mysql" description="Copy the lib so ant can see it" unless="no.ant.lib.dir">
      <mkdir dir="${user.home}/.ant"/>
      <mkdir dir="${user.home}/.ant/lib"/>
      <copy file="lib/mysql-connector-java-5.1.13-bin.jar" todir="${user.home}/.ant/lib"/>

      <!-- ant already missed picking up the jar - we have to restart -->
      <fail message="JDBC mysql class copied to ${user.dir}/.ant/lib/ - please restart ant" />
  </target>

  <!-- BUILD DATA SOURCES -->
  <target name="build" depends="init,setup_mysql,clean_data" description="Create and populate tables">

    <sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
      <transaction src="${sql.dir}/create_tables.sql"/>
      <transaction src="${sql.dir}/insert_data.sql"/>
    </sql>
  </target>

   <!-- CLEAN PROJECT -->
  <target name="clean" description="Cleans up project build">
    <!-- Don't clean data sources here - may get called by accident -->
  </target>

  <!-- Delete all tables and data -->
  <target name="clean_data" description="Deletes all data and tables">
    <echo>Dropping all database tables in ${sql.schema}...</echo>
    <property name="exec.command" value="mysqldump -u${sql.user} -p${sql.pass} --add-drop-table --no-data ${sql.schema} | grep ^DROP | mysql -u${sql.user} -p${sql.pass} ${sql.schema}" />
    <exec executable="sh">
      <arg value = "-c"/>
      <arg value="${exec.command}"/>
    </exec>

  </target>

</project>

希望这有帮助

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:

<project name="data_source" default="build">

  <!-- BUILD PROPERTIES -->
  <property file="build.properties"/>

  <!-- SQL Server Properties -->
  <property name="sql.driver" value="org.gjt.mm.mysql.Driver"/>
  <property name="sql.url" value="jdbc:mysql://127.0.0.1/datastore"/>
  <property name="sql.user" value="user"/>
  <property name="sql.pass" value="password"/>

  <!-- FILE LOCATIONS  -->
  <property name="sql.dir" location="sql"/>

  <!-- INITIALIZE PROJECT -->
  <target name="init" description="Initialize the project">
      <available property="no.ant.lib.dir" file="${user.home}/.ant/lib/" type="dir" />
  </target>

  <!-- SETUP MYSQL -->
  <target name="setup_mysql" description="Copy the lib so ant can see it" unless="no.ant.lib.dir">
      <mkdir dir="${user.home}/.ant"/>
      <mkdir dir="${user.home}/.ant/lib"/>
      <copy file="lib/mysql-connector-java-5.1.13-bin.jar" todir="${user.home}/.ant/lib"/>

      <!-- ant already missed picking up the jar - we have to restart -->
      <fail message="JDBC mysql class copied to ${user.dir}/.ant/lib/ - please restart ant" />
  </target>

  <!-- BUILD DATA SOURCES -->
  <target name="build" depends="init,setup_mysql,clean_data" description="Create and populate tables">

    <sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
      <transaction src="${sql.dir}/create_tables.sql"/>
      <transaction src="${sql.dir}/insert_data.sql"/>
    </sql>
  </target>

   <!-- CLEAN PROJECT -->
  <target name="clean" description="Cleans up project build">
    <!-- Don't clean data sources here - may get called by accident -->
  </target>

  <!-- Delete all tables and data -->
  <target name="clean_data" description="Deletes all data and tables">
    <echo>Dropping all database tables in ${sql.schema}...</echo>
    <property name="exec.command" value="mysqldump -u${sql.user} -p${sql.pass} --add-drop-table --no-data ${sql.schema} | grep ^DROP | mysql -u${sql.user} -p${sql.pass} ${sql.schema}" />
    <exec executable="sh">
      <arg value = "-c"/>
      <arg value="${exec.command}"/>
    </exec>

  </target>

</project>

Hope this helps

纵山崖 2024-07-20 12:49:58

当我将 *.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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文