using eclipseME and Antenna for preprocessing
Based on eclipseME 1.3.2 and Anteanna 0.9.13First setup eclipseME and
Anteanna as described in eclipseME docs. Now use
Export Antenna Build Files to create the intial build file setup.
To successfully run the build.xml, be sure to put the jdk's bin directory into the path. Otherwise an error like
[wtkpackage] JAR file creation failed with error -1 will indicate problems during preverification.
To do preprocessing in java, just add the //#if and //#endif directives (see also
http://antenna.sourceforge.net/#preprocess ) to the java file. To prevent compilation problems on doubled code lines, just also mark the one excluded during you programming wiht //#. Antenna will comment these lines in, also, if they are within a valid if/endif section.
I had to add the preprocesser task to my build.xml file (and also used the same sourcedir/destdir - so know, what you are doing...). It was also necessary to inclue the taskdef from anteanna's jar file, so that the wtkpreprocess is defined.
<!-- Preprocess any source file. -->
<target name="-preprocess" description="preprocess the source files">
<echo message="preprocessing for symbols: ${preprocessor.symbols}" />
<taskdef resource="antenna.properties">
<classpath location="${path.antenna.jar}"/>
</taskdef>
<wtkpreprocess srcdir="${basedir}/src" destdir="${basedir}/src" symbols="${preprocessor.symbols}">
</wtkpreprocess>
</target>Of course, the preprocess task needs to be called before build and build.xml was changed accordingly.
<!-- Build the classes that make up the midlet -->
<target name="build" depends="-initialize,-preprocess,-eclipseme-build"
description="Builds the classes that make up the project">
</target>
As you can see, the ant task uses ${preprocessor.symbols}. Just define them in the user-build.properites:
preprocessor.symbols=MIDP2,Nokia
Now go for your java sources and you may include something like
//#if MIDP2
//# setFullScreenMode(true);
//#endif
Code Page settings
There is a know code page/encoding issue with antenna and content of the jad-file. Also be sure to have UTF-8 encoding on or adjust the build-task of antenna to use your encoding to have proper class files created (within eclipse, the container code page is used instead UTF-8).