Purpose
This page describes the installation, configuration of a J2ME development environment.Overview
- Required Software
- Installation
- Configuration
- First J2ME project
- Deployment
- JAD test
- Mobile test
- Netbeans 4.1
- Links
- HelloWorld code
Step 1: required software
The following software will be used:- J2SDK1.5.0
- Eclipse 3.0.1: one of the best Java IDE ;-)
- J2ME Wireless toolkit 2.2
- EclipseME 0.7: Eclipse plugin to help develop J2ME code
- ProGuard 2.1: class file shrinker and obfuscator.
Step 2: Installation
- Install J2SDK as usual /rpm ...)
- Install Eclipse as usual (un-tar to /opt)
- Install J2ME Wireless Toolkit
The JWT comes as executable. Make it executable (chmod +x) and start it. Agree to licenses, set path to j2sdk bin-directory, enter path to install directory. - Install EclipseME plugin: Beginning with version 0.5.5, EclipseME is provided as an Eclipse "archive site.". Follow the instruction found here.
Step 3: Configuration
Check that Eclipse->Windows-Preferences contains "J2ME" entry.Choose platform components, right click and select "Wireless Toolkits".
Select the path to your WTK directory. Check that J2ME WTK, pltform definitions, profiles and configurations have been added.
Check that WTK works: start /usr/java/WTK2.2/bin/ktoolbar, load some sample projects and 'run' them.
Step 4: Project
Select File->New->Project. Select "show all wizards". Choose "J2ME Midlet Suite". Set path and project name.One the project, select New->Other, (show all wizards) and select "J2ME Midlet". Give it a name (HelloWorld).
Copy and paste the HelloWorld code into your class.
Compile it, choose "Run as-> Emulated J2ME Midlet".
Congratulation, your first Midlet is running.
Step 5: Deployment
Modify JAD file entries: double click on jad file, select midlets tab, add middlet. Give your middlet a name and select the class ("HelloWorld", selection may be broken, so just type the name of the class).Right click on the project, select J2ME->create package.
A new sub-directory (deployed) will appear. It contains a jar files (which contains your classes) and a jad file (which contains the description of your midlet).
ProGuard
Alternatively you can also use ProGuard, a java class file shrinker and obfuscator. Using it, class files will be smaller (important for J2ME devices, the example HelloWorld.class shrinks for 12k to 10k) and harder to reverse-engineer.
Download and unzip ProGuard. In Eclipse, go to Window->Preferences->J2ME. Set the proguard root directory.
Now, instead of creating a package, right click the project, select J2ME->"create obfuscated packages".
Step 6: JAD test
SimulatorCall $WTK_HOME/bin/runmidlet [jad-file].
- $WTK_HOME is the directory in which you have installed Wireless Toolkit
- jad file ist the deployed jad file, should be in [project_dir]/deployed
The simualtor should open and you can select the midlet (Hello World) that you want to execute.
Step 7: Mobile test
First you need a web server. Just upload your deployed jad and jar file into a directory of the web server.The web server must know the mime type of jad and jar files. For this, if you have control over the web server, add the following lines to apache httpd.conf file:
addtype application/java-archive jar addtype text/vnd.sun.j2me.app-descriptor jadIf you are like me and use a foreign web server, than add a .htaccess file which contains the above 2 files to the directory in which are the jad/jar files.
On your mobile, open the adress of your midlet.jad file: http://server/dir/[jad-file].
Netbeans 4.1
Now (Mai 2005) that Netbeans 4.1 is out, I can recommend you to use it as J2ME development platform instead of writing everything by yourself (which of course is good to know the basics).I will not write a new tutorial for Netbeans J2ME development, as there are some good tutorials out there.
- Eric Giguere: Exploring the netbeans MIDP Visual Designer
- J2ME MIDP Development for Netbeans IDE 4.1 QuickStart guide
Links and further information
- J2ME toolkits
- Nokia: http://www.forum.nokia.com/main/0,6566,st_p_50,00.html
- SonyEriccsson: http://developer.sonyericsson.com/site/global/home/p_home.jsp
- MIDP 2.0 phones and PDAs
- MIDP 2.0 development for Nokia 6600 with Eclipse and Antenna
- Antenna: An Ant-to-End Solution For Wireless Java
- Peter Rogers: Nokia 6230 analysis
- Learning:
- Sample apps:
- Further infos
HelloWorld Code
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloWorld extends MIDlet implements CommandListener { private Command exitCommand; private TextBox tbox; public HelloWorld() { exitCommand = new Command("Exit", Command.EXIT, 1); tbox = new TextBox("Hello world MIDlet", "Hello World!", 25, 0); tbox.addCommand(exitCommand); tbox.setCommandListener(this); } protected void startApp() { Display.getDisplay(this).setCurrent(tbox); } protected void pauseApp() {} protected void destroyApp(boolean bool) {} public void commandAction(Command cmd, Displayable disp) { if (cmd == exitCommand) { destroyApp(false); notifyDestroyed(); } } }
No comments:
Post a Comment