Monday, May 01, 2006

How to make JavaME project with Ant

I prepared Ant script that can be used for the most of Java ME projects. It encapsulates all low-level detail dealing with tools/callses from Java ME platform.

1. Specify project name and default target:

<project name="MyFirstMidlet" default="compile" basedir=".">

2. Define useful properties that will be used throughout the project:

  <property name="" value="c:/Java/j2me-2.3"/>

  <property name="" value="${}"/>
  <property name="src.dir" value="src"/>
  <property name="target.dir" value="target"/>

  <property name="midlet.command.line" value=""/>

3. Specify the classpath that includes core mobile API and required extension APIs, e.g.:

  <path id="mobile.classpath">
    <pathelement location="${}/lib/cldcapi11.jar"/>
    <pathelement location="${}/lib/midpapi20.jar"/>

    <pathelement location="${}/lib/wma20.jar"/>
    <pathelement location="${}/lib/mmapi.jar"/>
    <pathelement location="${}/lib/j2me-ws.jar"/>
    <pathelement location="${}/lib/jsr75.jar"/>
    <pathelement location="${}/lib/jsr082.jar"/>
    <pathelement location="${}/lib/jsr184.jar"/>
    <pathelement location="${}/lib/jsr179.jar"/>
    <pathelement location="${}/lib/jsr177.jar"/>
    <pathelement location="${}/lib/jsr211.jar"/>

4. We need to create string version of our classpath. It will be used for executables, like "preverified.exe" and "emulator.exe":

    <property name="mobile.classpath" refid="mobile.classpath"/>

5. Prepare "compile" target. Keep in mind that target attribute should be on "1.1" level:

  <target name="compile">
    <mkdir dir="${target.dir}/classes"/>

    <javac srcdir="${src.dir}" destdir="${target.dir}/classes"
           source="1.1" target="1.1"/>


6. Compiled classes should be "preverified". It means that each class file in "classes" directory will have corresponding "preverified" class file in "preverified" directory.

  <target name="preverify" depends="compile">
    <mkdir dir="${target.dir}/preverified"/>

    <exec executable="${}/bin/preverify">
      <arg line="-classpath ${mobile.classpath}"/>
      <arg line="-d ${target.dir}/preverified"/>
      <arg line="${target.dir}/classes"/>

7. Resulting jar file will contain "preverified" classes and resources from "res"

  <target name="jar" depends="preverify">
    <mkdir dir="${target.dir}/bin"/>

    <jar basedir="${target.dir}/preverified"
      <fileset dir="res"/>

    <copy file="bin/${}.jad"


8. In order to run generated artifact you have to launch the emulator. You can run
emulator as executable file or as java class.

- as executable:

  <target name="run2" depends="jar">
    <exec executable="${}/bin/emulator">
      <!-- device: DefaultColorPhone, DefaultGrayPhone, MediaControlSkin, QwertyDevice -->
      <arg line="-Xdevice:DefaultColorPhone"/>
      <arg line="-Xdescriptor:${basedir}/${target.dir}/bin/${}.jad"/>

      <arg line="-classpath ${mobile.classpath};${basedir}/${target.dir}/bin/${}.jar"/>

- as java class:

  <target name="run" depends="jar">
    <java fork="yes" classname="com.sun.kvem.environment.EmulatorWrapper">
      <sysproperty key="kvem.home" value="${}"/>
      <sysproperty key="java.library.path" value="${}/bin"/>
      <sysproperty key="sun.java2d.ddlock" value="true"/>
      <sysproperty key="sun.java2d.gdiblit" value="false"/>

      <arg line="-Xdevice:DefaultGrayPhone"/>
      <arg line="-Xdescriptor:${basedir}/${target.dir}/bin/${}.jad"/>

      <arg line="-classpath ${mobile.classpath};${target.dir}/bin/${}.jar"/>
      <arg line="${}"/>
      <arg line="${midlet.command.line}"/>
      <arg line="0"/>


Anonymous said...

Find and download what you need at Rapidshare Search Engine.
Top Site List Free Proxy Site Free Download mp3 Michael Jackson song All Michael Jackson Lirics Oes Tsetnoc Mengembalikan Jati Diri Bangsa Download Mp3 Gratis

Daniela said...

Interesting post. I have been wondering about this issue,so thanks for posting. I’ll likely be coming back to your blog. Keep up great writing. Find your great Travel News and sing the songs at Free Song Lyric or you can watch the drama at Korea Drama Online one of great korea drama is A Love to Kill if you go to travel to Indonesia learn Learn Indonesia Language first! And find your home cari rumah or make a blog Belajar membuat Blog find your home again rumah dijual and again at jual rumah then if you want buy a new laptop see the Laptop Price List or you can buy a New Blackberry and then take care your Health & Jewerly.

Anonymous said...

Good dispatch and this fill someone in on helped me alot in my college assignement. Gratefulness you on your information.

Anonymous said...

Brim over I agree but I about the list inform should have more info then it has.

Anonymous said...

Genial fill someone in on and this mail helped me alot in my college assignement. Thanks you on your information.

Anonymous said...

Microsoft Office 2010
Office 2010
Office 2007
Microsoft Office
Microsoft Office 2007
Office 2007 key
Office 2007 download
Office 2007 Professional
Windows 7
Microsoft outlook 2010

Anonymous said...

Today I was specially registered at a forum to participate in discussion of this question.

2011bagnews said...

ray ban 3186 are usually smooth. they're made having a streamlined look. one more pattern may be the wraparound Ray ban sunglasses.They are pretty well-liked amidst sports activities personalities generally because of its futuristic appeal. These wraparound ray ban 3212 typically have polycarbonate lens and sturdy grip to produce total vision security accompanied using the awesome and classy look. dfgkcxy0rtw The display is immensely common and has led towards the generation of the really personal manufacturer title ray ban 3269 , amongst other products and solutions which include a movie game.All Ray ban sunglasses lens are created of shatter evidence polycarbonate and offer 100% ultra violet protection. So, even as you have older,
ray ban 3322 you can even now ride the street with obvious and sharp vision.Every pair of genuine Orange County Ray ban sunglasses arrives with it's personal leather-based bound case. several huge and well-liked custom homes on a regular basis roll-out their ray ban 3359 ranges that are prepared with exceptional vision gear, ideal acuity, and assortment of features.