tags:

views:

1826

answers:

1

Hi,

We have an ant build script for a project we're developing for a PDA. In eclipse we have a load of referenced libraries and I know how to get them to work when we run the jar on the PDA because we have a .lnk file where you can add the external libraries simply by adding the following:

512#"\J9\PPRO11\bin\j9.exe" -jcl:ppro11 -cp "\dist\WiFiTest.jar;\placelab\lib\placelab.jar" j2medemo.wifi.WiFiTest

Adding whatever libraries we need after the -cp argument. However, I have no idea how to replicate this in the ant file (no idea is actually an exaggeration but after reading all the documentation I still don't understand it).

We have the following .

<target name="jar" depends="prepare">
 <delete file="${dist}/${appname}.jar"/>
 <delete file="${dist}/MANIFEST.MF"/>
 <manifest file="${dist}/MANIFEST.MF">
    <attribute name="Built-By" value="${user.name}"/>
    <attribute name="Main-Class" value="j2medemo.GUI.MapPanel"/>
</manifest>
<jar destfile="${dist}/${appname}.jar"
     basedir="${classes}"
     includes="**/*.class, **/*.jpg, **/*.gif,**/*.png,**/*.xml"
     manifest="${dist}/MANIFEST.MF"
     />
</target>

I have tried adding everywhere I can think of but it doesn't help. Can I just add it to the the include part?

Secondly, we have a run target:

<target name="run" description="run" depends="jar">
    <exec dir="${j9bin}" executable="${j9bin}\j9.exe">
        <arg line="-jcl:ppro11 -cp '${dist}\${appname}.jar;placelab\lib\placelab.jar' ${mainclass}"/>
        <env key="JAVA_HOME" path="${j9home}"/>
    </exec>
</target>

And I wanted to change it to run a different class so I created the following two targets:

<target name="jarSAX" depends="prepare">
 <delete file="${dist}/SAXParse.jar"/>
 <delete file="${dist}/MANIFEST.MF"/>
 <manifest file="${dist}/MANIFEST.MF">
    <attribute name="Built-By" value="${user.name}"/>
    <attribute name="Main-Class" value="j2medemo.Routes.SAXParse"/>
</manifest>
<jar destfile="${dist}/SAXParse.jar"
     basedir="${classes}"
     includes="**/*.class, **/*.jpg, **/*.gif,**/*.png,**/*.xml"
     manifest="${dist}/MANIFEST.MF"
     />
</target>

And

<target name="runSAXParser" description="run" depends="jarSAX">
        <exec dir="${j9bin}" executable="${j9bin}\j9.exe">
            <arg line="-jcl:ppro11 -cp '${dist}\SAXParse.jar' j2medemo.Routes.SAXParse"/>
            <env key="JAVA_HOME" path="${j9home}"/>
        </exec>
    </target>

But if I try and run this I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: j2medemo.Routes.SAXParse

If anyone has any ideas/solutions for either questions that would be most helpful.

Many thanks for your time.

P.S The full ant file is here in case that helps.

Cheers,
Adam

A: 

From what I can tell, you need to add the classpath elements to the manifest. Should look something like this:

 <manifest file="${dist}/MANIFEST.MF">
    <attribute name="Built-By" value="${user.name}"/>
    <attribute name="Main-Class" value="j2medemo.Routes.SAXParse"/>
    <attribute name="Class-Path" value="WiFiTest.jar;placelab.jar"/>
 </manifest>

The classpath entries should be relative to the location of the Jar in the distributable. From there, you should be able to execute the jar directly (using the -jar command line option, I'm not sure what this is for J9). Should be similar to the analogous Java call:

java -jar MainJar.jar
James Van Huis