Header
Home | Sitemap Set as homepage | Add to favorites
  Search the Site     » Advanced Search
Sections



Compiling a MIDlet

by

image

Compiling a MIDlet

Writing MIDlets is an example of cross-compiling, where you compile code on one platform and run it on another. In this case, you'll be compiling a MIDlet using J2SE on your desktop computer. The MIDlet itself will run on a mobile phone, pager, or other mobile information device that supports MIDP.

The J2ME Wireless Toolkit takes care of the details as long as you put the source code in the right directory.

  1. Start the toolkit, called KToolbar.

  2. Choose New Project... from the toolbar to create a new project.

  3. When the J2ME Wireless Toolkit asks you for the name of the project and the MIDlet class name, use "Jargoneer" for both.

  4. Click OK twice to dismiss the project settings window.

Figure 2-1 shows the New Project dialog.

Click To expand
Figure 2-1: Creating a new project with the J2ME Wireless Toolkit

The J2ME Wireless Toolkit represents projects as subdirectories of its apps directory. The following diagram shows the contents of the Jargoneer directory after the new project is created.

Save the source code as Jargoneer.java in the project's src directory. You can simply click the Build button in the J2ME Wireless Toolkit tool bar to compile the open project.

Behind the scenes, the J2ME Wireless Toolkit uses J2SE's compiler. Normally, when you're compiling J2SE source code, the CLASSPATH environment variable points to all the classes that your source code needs to know about. When you use javac to compile a file, there are some implied APIs that get included, like the classes in java.lang. With MIDlets, however, the situation is a little more complicated. Say that you use the java.lang.System class in your MIDlet. How do you (or how does the J2ME Wireless Toolkit) let the compiler know that you want to use the MIDP version of this class, not the J2SE version?

The answer is a command line option, -bootclasspath. This option lets you point to a classpath that describes the fundamental APIs against which you will be compiling your source code. In our case, this option should be used to specify the classes directory in the MIDP reference implementation installation. If you install the MIDP reference implementation, the command line looks like this:

javac -bootclasspath \midp\classes Jargoneer.java

You will need to adjust the path to classes if you installed the MIDP reference implementation in a different location.



480 times read

Related news

» Compilation
by admin posted on Sep 26,2007
» Designing and Coding
by admin posted on Sep 26,2007
» Using Parsers in the J2ME Wireless Toolkit
by admin posted on Nov 17,2006
» Using the J2ME Wireless Toolkit
by admin posted on Sep 26,2007
» MIDP Application Program Structure
by admin posted on Sep 26,2007


More Top News
Cisco Wireless Networking
Most Popular
Featured Author