dashtebash dashtebash - 5 months ago 17
Java Question

Compiling j2me using Ant

I have created a J2ME project after referring to this article J2MEUsingAntwithJ2ME. Now I am having problems in adding resources (such as images) and libraries (such as jar and zip files).
I have copied the resources in the

res
folder as shown in this article but when I extract the
.jar
file, it does not have any resources.

Answer

From the sample:

<jar basedir="${build}/preverifiedobf"
     jarfile="${build}/bin/${program_name}.jar"
     manifest="bin/MANIFEST.MF">
  <fileset dir="${top}/${res}">
    <include name="${package_name}/*.png"/>
  </fileset>
</jar>

This will only include *.png files which are in /res folder. If you want to include more types, add more <include> lines or include "${package_name}/**".

If you want to include the content of existing .jar files, you can unjar them like this:

<mkdir dir="${build}/libs"/>
<unjar src="yourlibrary.jar" dest="${build}/libs" />

Then you can jar them up again:

<jar basedir="${build}/preverifiedobf"
     jarfile="${build}/bin/${program_name}.jar"
     manifest="bin/MANIFEST.MF">
  <fileset dir="${top}/${res}">
    <include name="${package_name}/*.png"/>
  </fileset>
  <fileset dir="${build}/libs">
    <include name="**/*"/>
  </fileset>
</jar>

The Apache Ant manual contains a lot of examples for all the supported tags.