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:\SOFTWARE\Android\TestBound>ant modify
Buildfile: D:\SOFTWARE\Android\TestBound\build.xml
modify:
[iOffloadMaker] Offload Maker is executing...
BUILD FAILED
D:\SOFTWARE\Android\TestBound\build.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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.