java.lang.NoClassDefFoundError, Ant task could not see classes in jar inside jar

I wrote Java tool (in this case is iOffloadMaker) which also contains own-defined Ant Task as the main launcher to launch the tool with Ant. I bundled all external jar libraries into delivered my tool's jar. I also provide a simple Ant build.xml file to launch my tool:

<?xml version="1.0"?>
<project name="TestBound" default="main" basedir=".">
    <!-- Sets varables which can later be used. -->
    <property name="src.dir" value="src" />
    <property name="build.dir" value="bin" />
    <property name="dist.dir" value="dist" />
    <property name="libs.dir" value ="libs" />


    <path id="build.classpath">
        <fileset dir="${libs.dir}">
            <include name="**/*.jar"/>
        </fileset>

        <pathelement location=".iOffloadMaker.jar"/>
    </path>
        <!-- define offload maker task -->

    <taskdef name="iOffloadMaker" classname="com.richardle.ioffload.OffloadMakerTask" classpathref= "build.classpath"/>             

    ... 

        <!-- Creates the  build, docs and dist directory-->
    <target name="modify" description="modify the source code" >        
        <iOffloadMaker projectFolder="${basedir}">          
        </iOffloadMaker>

    </target>

         ... 

    <target name="main" depends="compile">
        <description>Main target</description>
    </target>
</project>

The thing is that, Ant Task could not refer to classes in jar libraries inside my tool jar file. Hence, when I run ant, it throw exception as

D:SOFTWAREAndroidTestBound>ant modify
Buildfile: D:SOFTWAREAndroidTestBoundbuild.xml

modify:
[iOffloadMaker] Offload Maker is executing...

BUILD FAILED
D:SOFTWAREAndroidTestBoundbuild.xml:40: java.lang.NoClassDefFoundError: org/
xmlpull/v1/XmlPullParserException
        at com.richardle.ioffload.offloadmaker.ApplicationProject.<init>(Applica
tionProject.java:30)
        at com.richardle.ioffload.offloadmaker.OffloadMaker.execute(OffloadMaker
.java:121)
        at com.richardle.ioffload.OffloadMakerTask.execute(OffloadMakerTask.java
:26)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)

I am sure that all necessary libs are bundled into iOffloadMaker.jar. The thing is that Ant Task loader could not see classes of dependency jars inside my jar file.

If I do not bundled all dependencies into jar, but deliver them in dependency folder along with iOFfloadMaker.jar, it work as I expected. But I want to bundle all dependencies and my tool source code into one delivery jar file.

Is there a solution for this problem?


The standard Java classloader isn't able to handle recursive JARs (ie JARs that are bundled inside of other JARs).

This page lists a couple of solutions for that: http://www.jdotsoft.com/JarClassLoader.php

Please let me know which one worked for you.

链接地址: http://www.djcxy.com/p/44396.html

上一篇: Java扩展应用程序类加载器?

下一篇: java.lang.NoClassDefFoundError,Ant任务无法在jar中的jar中看到类