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



Compilation

by

image

Compilation
The next step in the actual development cycle after creating your program is to compile the
program source. Before you attempt compilation, make sure your shell environment's command
path list includes the path to the directory that contains the J2ME utilities on your system.
The general form of the compilation line is
$ javac –d <tmpclasses dir> -bootclasspath <midpapi.zip location> \
<location of Java source file(s)>
The –d directive tells the compiler the directory in which to write the unverified compiled classes.
The -bootclasspath directive indicates the location of the midpapi.zip file, which comes
with Java Software's J2ME Wireless Toolkit and contains all the MIDP classes you need to write
J2ME applications. Development environments from commercial vendors also include this file.
The -bootclasspath directive also tells the compiler to override any CLASSPATH
specification you might have set in your shell environment. Note that this must be a relative
pathname, relative to the project's root directory. Finally, you specify the path names of the Java
source files you are compiling.
To compile the HelloWorld MIDlet suite from the apps/HelloWorld/ directory, use the
following command:
$ javac -d tmpclasses \
-bootclasspath ../../lib/midpapi.zip src/HelloWorld.java
$
The –d directive tells the compiler to write the unverified compiled classes to the tmpclasses
directory under the HelloWorld/ directory. The -bootclasspath directive specifies a
pathname relative to the current directory. Finally, the last argument specifies the relative
pathname of the HelloWorld.java source file.
You learned in chapter 1 that the MIDP and CLDC libraries define the complete platform for
building MIDP applications. In consequence, you don't need to include the path of any J2SE
installation in your environment's CLASSPATH when compiling your applications. In fact, you
can't include it. If you do, you'll get compilation errors because the compiler will find conflicting
definitions between the J2SE and J2ME libraries.
After compiling your files, the tmpclasses directory contains the unverified .class files:
$ ls -l tmpclasses/
16
total 0
-rw-r--r-- 1 vartan None 922 HelloWorld.class
$
605 times read

Related news

» Designing and Coding
by admin posted on Sep 26,2007
» Compiling a MIDlet
by admin posted on Nov 17,2006
» Preverification
by admin posted on Sep 26,2007
» Using the J2ME Wireless Toolkit
by admin posted on Sep 26,2007
» Packaging
by admin posted on Sep 26,2007


More Top News
Cisco Wireless Networking
Most Popular
Featured Author