我有一个带有蚂蚁任务的jar。我的com / mebigfatguy / stringliterals / antlib.xml是
<antlib xmlns:stringliterals="ant:com.mebigfatguy.stringliterals">
<taskdef name="stringliterals" classname="com.mebigfatguy.stringliterals.StringLiteralsTask"/>
</antlib>
运行jar tf stringliterals.jar我得
META-INF/
META-INF/MANIFEST.MF
com/
com/mebigfatguy/
com/mebigfatguy/stringliterals/
com/mebigfatguy/stringliterals/antlib.xml
com/mebigfatguy/stringliterals/SLClassVisitor.class
com/mebigfatguy/stringliterals/StringLiteralsTask.class
com/mebigfatguy/stringliterals/SLMethodVisitor.class
com/mebigfatguy/stringliterals/Literal.class
META-INF/maven/
META-INF/maven/com.mebigfatguy.stringliterals/
META-INF/maven/com.mebigfatguy.stringliterals/stringliterals/
META-INF/maven/com.mebigfatguy.stringliterals/stringliterals/pom.xml
META-INF/maven/com.mebigfatguy.stringliterals/stringliterals/pom.properties
com/mebigfatguy/org/
com/mebigfatguy/org/objectweb/
com/mebigfatguy/org/objectweb/asm/
com/mebigfatguy/org/objectweb/asm/AnnotationVisitor.class
com/mebigfatguy/org/objectweb/asm/AnnotationWriter.class
com/mebigfatguy/org/objectweb/asm/Attribute.class
com/mebigfatguy/org/objectweb/asm/ByteVector.class
com/mebigfatguy/org/objectweb/asm/ClassReader.class
com/mebigfatguy/org/objectweb/asm/ClassVisitor.class
com/mebigfatguy/org/objectweb/asm/ClassWriter.class
com/mebigfatguy/org/objectweb/asm/Context.class
com/mebigfatguy/org/objectweb/asm/Edge.class
com/mebigfatguy/org/objectweb/asm/FieldVisitor.class
com/mebigfatguy/org/objectweb/asm/FieldWriter.class
com/mebigfatguy/org/objectweb/asm/Frame.class
com/mebigfatguy/org/objectweb/asm/Handle.class
com/mebigfatguy/org/objectweb/asm/Handler.class
com/mebigfatguy/org/objectweb/asm/Item.class
com/mebigfatguy/org/objectweb/asm/Label.class
com/mebigfatguy/org/objectweb/asm/MethodVisitor.class
com/mebigfatguy/org/objectweb/asm/MethodWriter.class
com/mebigfatguy/org/objectweb/asm/Opcodes.class
com/mebigfatguy/org/objectweb/asm/Type.class
com/mebigfatguy/org/objectweb/asm/TypePath.class
com/mebigfatguy/org/objectweb/asm/TypeReference.class
com/mebigfatguy/org/objectweb/asm/signature/
com/mebigfatguy/org/objectweb/asm/signature/SignatureReader.class
com/mebigfatguy/org/objectweb/asm/signature/SignatureVisitor.class
com/mebigfatguy/org/objectweb/asm/signature/SignatureWriter.class
你可以看到任务类在那里
我把jar放在〜/ .ant / lib中,当我尝试运行一个像这样引用它的任务时:
<target name="literals" xmlns:stringliterals="antlib:com.mebigfatguy.stringliterals" description="generate report of string literals used in code">
<stringliterals:stringliterals>
<classpath refid="fb-contrib.classpath"/>
</stringliterals:stringliterals>
</target>
我得到了
文字:
解析buildfile jar:file:/home/dave/.ant/lib/stringliterals-0.2.0.jar!/com/mebigfatguy/stringliterals/antlib.xml,URI = jar:file:/ home / dave /。来自zip文件的ant / lib / stringliterals-0.2.0.jar!/com/mebigfatguy/stringliterals/antlib.xml 查找类com.mebigfatguy.stringliterals.StringLiteralsTask
建立失败 /home/dave/dev/fb-contrib/build.xml:245:执行此行时发生以下错误: jar:file:/home/dave/.ant/lib/stringliterals-0.2.0.jar!/com/mebigfatguy/stringliterals/antlib.xml:2:taskdef class com.mebigfatguy.stringliterals.StringLiteralsTask找不到 使用类加载器AntClassLoader [] 在org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:607) 在org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:237) 在org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:177) 在org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:428) 在org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:277) 在org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:874) at org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:307) 在org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:284) 在org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:263) at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:429) at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163) at org.apache.tools.ant.Task.perform(Task.java:347) 在org.apache.tools.ant.Target.execute(Target.java:435) 在org.apache.tools.ant.Target.performTasks(Target.java:456) 在org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) 在org.apache.tools.ant.Project.executeTarget(Project.java:1364) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 在org.apache.tools.ant.Project.executeTargets(Project.java:1248) 在org.apache.tools.ant.Main.runBuild(Main.java:851) 在org.apache.tools.ant.Main.startAnt(Main.java:235) 在org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) 在org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) 引起:java.lang.ClassNotFoundException:com.mebigfatguy.stringliterals.StringLiteralsTask 在org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1366) 在org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315) 在org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) 在java.lang.Class.forName(Class.java:348) 在org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:579) ......还有21个
我之前已经多次这样做过没有任何问题,但这次我不知道我哪里出错了。有没有办法调试这个类加载器问题?
答案 0 :(得分:0)
问题原来是格式错误的清单文件。遗憾!