J2me Gaming : Problem with Creating build(jar) for nokia phones

Posted on 2004-04-29
Medium Priority
Last Modified: 2012-05-04

I am having trouble in making a package (jar) for  nokia phones. I have been tring using J2ME wireless kit, Eclipse, Nokia development Suite and IBM Device developer but havent been able to make a perfect package out of it.

I have even downloaded the plugins for Eclips but not able to configure it properly. I did every thing according to the specifications. but while building project i get the error "Problem while running the build script ....." .

Overall i want create a jar package and obufuscate that for Nokia phones.Its real urgent. Wud want someone to guide me on all the necessary.

Thanks in advance.
Question by:rayan2057
  • 2
LVL 15

Expert Comment

ID: 10947750
What line is being indicated as the source of the problem in your build script?

What "script" are you referring to?

Are you using Ant to build the JAD/JAR?

I would recommend the Antenna ant extension: http://antenna.sourceforge.net/

When you say that you need to do a build for Nokia phones, do you mean you're using the Nokia APIs (eg. the Nokia UI or WMA?)

Author Comment

ID: 10949462
I am using Nokia Specific classes like FillCanvas and Sound so i am not able to make build

>> What "script" are you referring to?
  I am not referring to any script the plugin i have installed does not specify usage of any build script
  Plugin is: com.siptech.j2me
About "Antenna" is it a plugin for "Apache Ant" or it is a stand alone tool ?
LVL 15

Accepted Solution

jimmack earned 300 total points
ID: 10949699
Antenna is an extension for Ant.  In order to use the Antenna facilities (eg. the targets for creating JADs, building, packaging, obfuscating etc.), you need to declare the targets in your Ant build file (build.xml).

Here is a same Ant build file that is a cut-down version of one I'm currently using.  This includes the Wireless Messaging API for Nokia 3410 (just to demonstrate how to include external libraries):

The wtkjad task is used to create the initial JAD file for the MIDlet.
The wtkpreprocess task handles the parts of the source that are conditionally included using the #ifdef support provided by Antenna, eg. in this case the following code:

//#ifdef WMA_ENABLED
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;

is included.  If the symbols="WMA_ENABLED" text is missed, the preprocessor changes the above code to:

//#ifdef WMA_ENABLED
//import javax.wireless.messaging.MessageConnection;
//import javax.wireless.messaging.TextMessage;

The preprocessed source code is now in the preproc directory and the wtkbuild task compiles this into the target directory using the bootclasspath to use the Nokia APIs rather than the standard ones.  I've also set the preverification within this task too.

The wtkpackage task then builds the JAD and JAR files, updating them with extra info (eg. config and profile), preverifies again (no particular reason for this) and obfuscates the JAR.  Note that the JAR file includes all the files in the target directory and the res (resource) directory except those specified by the excludes clause.

<?xml version = '1.0' encoding = 'ISO-8859-1' ?>
<project name="Sample" default="build" basedir="..">
  <property name="wtk.home" value="/usr/java/j2mewtk104"/>
  <property name="projroot" value="/home/jim/eclipse/workspace/MyProject" />
  <property name="src" value="${projroot}/src"/>
  <property name="res" value="${projroot}/res"/>
  <property name="preproc" value="${projroot}/preproc"/>
  <property name="target" value="${projroot}/target"/>
  <property name="target_dist" value="${projroot}/bin"/>
  <property name="version" value="1.0.0"/>
  <property name="nokiaWMA" value="/usr/java/nokia/3410/lib/classes.zip"/>
  <taskdef resource="antenna.properties"/>

  <target name="clean_build_dirs">
    <delete dir="${target}"/>
    <mkdir dir="${target}"/>
    <delete dir="${preproc}"/>
    <mkdir dir="${preproc}"/>
  <target name="clean_target_dir">
    <delete dir="${target_dist}"/>
    <mkdir dir="${target_dist}"/>
  <target name="build3410" depends="clean_build_dirs">
    <wtkjad jadfile="${target_dist}/MyProject.jad"
            vendor="Objective Software Services Ltd."

        <midlet name="MyProject"

    <wtkpreprocess srcdir="${src}"
    <wtkbuild srcdir="${preproc}"

    <wtkpackage jarfile="${target_dist}/TrainFinder.jar"
        <fileset dir="${target}">
          <exclude name="**/Monitor*"/>
        <fileset dir="${res}">
          <exclude name="**/*9.dat"/>

Assisted Solution

JavaInTheMorning earned 300 total points
ID: 10957319
Since it's urgent, I think that the best way for now is to use the command line to do all that:
First compile the project:
d:\j2sdk1.4.0_02\bin\javac -g:none -target 1.1 *.java
// Then Jar it (change the dir to your Java dir).
d:\j2sdk1.4.0_02\bin\jar cfmv applicationName.jar manifest.mf *.class *.png sound\*.wav
// Then preverify it:
d:\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0\bin\preverify.exe -classpath d:\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0\lib\classes.zip;.\classes; -d .\verified applicationName.jar
copy verified
And then you can obfuscate it:
java -classpath c:\wtk104\bin\retroguard.jar;c:\wtk104\wtklib\emptyapi.zip;D:\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0\lib\classes.zip RetroGuard applicationName.jar applicationName2.jar ignore.rgs

D:\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0\bin\preverify.exe -classpath D:\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0\lib\classes.zip;.\classes applicationName2.jar

copy output\applicationName2.jar
del applicationName.jar
ren applicationName2.jar applicationName2.jar
// Then update the Jad file so it would state the correct size of the Jar file (manually).

Don't forget to change the paths to YOUR paths (nokia, jdk, etc.)
Hope it helps,


Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Hopefully this article will help someone who's had the same issues I had. I have a Dell Wireless 1390 WLAN Mini-Card and Windows 7, and for the past couple of days I was beyond frustrated because my wireless laptop was not able to access the Inte…
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question