【问题标题】:Taskdef class com.temp.install.common.action.UserInstallDirRule cannot be found using the classloader AntClassLoader使用类加载器 AntClassLoader 找不到 Taskdef 类 com.temp.install.common.action.UserInstallDirRule
【发布时间】:2017-09-20 12:46:15
【问题描述】:

我创建了一个 jar,其中包含 .class 文件和使用以下 jar 代码执行类文件所需的依赖库

<target name="jar" depends="clean">
    <jar destfile="${basedir}/lib/HelloWorld.jar">
        <zipgroupfileset dir="${basedir}/lib" includes="*.jar" />
        <fileset dir="${basedir}" includes="/com/temp/**" />
        <fileset dir="${basedir}" includes="build.properties"/>
        <manifest>
        <attribute name="Class-Path" value="./HelloWorld.jar"/>
        </manifest>
    </jar>
</target>

现在我已经编写了其他 build.xml 来使用这个 jar 运行 taskdef 操作,但是当我尝试使用 taskdef 操作调用类文件时会发生以下错误,即使类文件及其依赖项存在于同一个 jar 中。

构建失败 C:\Users\kh2139\Desktop\New folder\build.xml:4: taskdef class com.temp.install.common.action.UserInstallDirRule 找不到 使用类加载器 AntClassLoader[C:\Users\kh2139\Desktop\New folder\HelloWorld.jar]

在下面附加我的 build.xml 代码,该代码用于在 HelloWorld.jar 上运行 taskdef 操作

<?xml version="1.0" encoding="ISO-8859-1"?>
    <project name="MyTask" basedir="." default="use">
<target name="use" description="Use the Task" >
    <taskdef name="helloworld1" classname="com.temp.install.common.action.UserInstallDirRule" classpath="HelloWorld.jar"/>
    <helloworld1/>
    <taskdef name="helloworld" classname="com.temp.install.common.action.EncryptionGUID" classpath="HelloWorld.jar"/>
    <helloworld/>
</target>
</project>

PS:当我在放置 HelloWorld.jar 的位置指定 lib 文件夹并在 taskdef 操作中为 lib 文件夹提供类路径时,我可以成功运行 build.xml 文件而不会出错。

但我的问题是我想使用同一个 jar 来包含执行类时使用的依赖项。

【问题讨论】:

  • @datv 我已经发布了我之前的评论作为答案。我还删除了原始评论,以免重复答案。

标签: java xml jar ant taskdef


【解决方案1】:

错误表示Java在HelloWorld.jar中找不到UserInstallDirRule.class。要确定HelloWorld.jar 是否包含该类,请尝试运行JDK 附带的jar.exe 程序。

以下是在 Windows 命令提示符中运行 jar.exe 的示例:

C:\>jar.exe tf "C:\Users\kh2139\Desktop\New folder\HelloWorld.jar"

输出将显示 UserInstallDirRule.class 是否在 JAR 文件中。

【讨论】:

  • +1 用于将“Taskdef class...AntClassLoader”翻译成“错误表示Java在HelloWorld.jar中找不到UserInstallDirRule.class”
猜你喜欢
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 2015-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多