Compilation
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
|
|
|
|