使用类加载器AntClassLoader找不到Taskdef类com.temp.install.common.action.UserInstallDirRule

时间:2017-04-24 00:07:36

标签: java xml jar ant taskdef

我创建了一个带有.class文件的jar和使用下面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来包含执行类时使用的依赖项。

1 个答案:

答案 0 :(得分:1)

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

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

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

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