Programming Java 2 Micro Edition for Symbian OS 2004 (779882), страница 16
Текст из файла (страница 16)
Commands canbe set to true, or false when they are not required. This gives thedeveloper the option of adding in an obfuscation step between compilingand pre-verification. An extra target could be inserted as well, to deal withpackages from third-party developers. Ant really is flexible, and this is oneof the reasons why it has been embraced by a growing number of Javadevelopers. It facilitates the handling of builds for different applications ornumerous builds for the same application, saving developer time duringdevelopment as well as smoothing the communication between differentmembers of a development team.
Whichever way it is used it provides adefined and reproducible build for a MIDlet (with the use of Antenna) orfor any other Java application for that matter.Before we look at installation and execution let’s have a look at anexample build.xml file. We have built one for use with the Demo Racerapplication discussed in Chapter 5.
Configuration of Ant and Antenna forMIDP 2.0 using the Wireless Toolkit version 2.1 is a little more difficultthan for previous editions. Version 2.1 splits the CLDC and MIDP packagesinto JAR files for each version. Therefore the <wtk home>/lib directorycontains cldcapi10.jar, cldcapi11.jar, midpapi10.jar andmidpapi20.jar files. This split has to be reflected in the build.xmlfile, such as the one below. This build file was taken from the ”hello”example included in the Antenna source ZIP file and then adapted forour needs.<?xml version="1.0"?><project name="DemoRacer" default="build" basedir="."><!-- Define the WTK home directory, needed by the tasks.
--><property name="wtk.home" value="D:/WTK21"/><!-- Define the MIDP API: either 1.0 or 2.0 can be used. --><property name="wtk.midpapi" value="${wtk.home}/lib/midpapi20.jar"/><!-- Define optional properties for this project. --><property name="midlet.name" value="DemoRacer"/><property name="midlet.home"value="${wtk.home}/apps/${midlet.name}"/><!-- Define the tasks. --><taskdef resource="antenna.properties"/><target name="clean"><delete failonerror="false" dir="classes"/><delete failonerror="false"><fileset dir="."><exclude name="build.xml"/></fileset></delete></target><target name="build">INTRODUCTION TO TOOLS FOR MIDP61<!-- Copy a JAD file from the WTK demo applications.Caution: Ant only copies this the first time.
Alsomake a directory to compile into. --><copy file="${midlet.home}/bin/${midlet.name}.jad" todir="."/><mkdir dir="classes"/><!-- Compile everything, but don’t preverify (yet). --><wtkbuild srcdir="${midlet.home}/src"destdir="classes"preverify="false"/><!-- Package everything. Most of the necessary information iscontained in the JAD file.
Also preverify the result thistime. To obfuscate everything, set the correspondingparameter to "true" (requires RetroGuard or ProGuard).The version parameter increments the MIDlet-Version byone. --><wtkpackage jarfile="${midlet.name}.jar"jadfile="${midlet.name}.jad"classpath="${wtk.home}/lib/cldcapi10.jar"obfuscate="false"preverify="true"autoversion="true"><!-- Package our newly compiled classes and theresources from the WTK demo application. --><fileset dir="classes"/><fileset dir="${midlet.home}/res"/></wtkpackage><!-- Start the MIDlet suite --><wtkrun jadfile="${midlet.name}.jad"device="DefaultColorPhone"trace="class,gc" wait="true"/></target></project>There are seven areas of interest in this build.xml file:• Wireless Toolkit location – in the property wtk.home; Antenna reliesupon functionality provided by the WTK, so this property is essential• MIDP API location – the WTK 2.1 defines two sets of API, to allow forbackwards compatibility when building MIDlets; we have chosen themidpapi20.jar file• the Antenna properties file – defined in a task definition as a resourceand set to antenna.properties, this file specifies the classpath ofthe antenna classes within the antenna-bin-0.9.11.jar file• the build target – as the default build (we can define more than onewithin the same configuration file), this defines what the build willactually includeIn this case, we copy the existing JAD file to a new location, althoughwe could use this build.xml file to create a new one.
The MIDlet62GETTING STARTEDsource is defined along with the destination for the compiled classes.The emulator execution and packaging are wrapped in this build.• the wtkpackage command – this creates the JAR and if the JAD fileis present, it tries to update the MIDlet-Jar-Size and MIDletJar-URL attributes; it performs obfuscation and pre-verification (ifthose attributes are set to true) and increments the version numberof the MIDlet• the build classpath – the WTK 2.1 splits the CLDC classes into CLDC1.0 and CLDC 1.1, so we need to specify the classes against which thepre-verifier should verify; we have chosen CLDC 1.0; the pre-verifierwon’t execute successfully if this property is not set correctly• running in an emulator – once all this has been completed successfullythe specified emulator will be run according to the device set in thedevice property.InstallationBuilds are available from the Ant website for both Windows and Linux/Unixdevelopers, though we are only concerned with Windows installation.Developers can choose either a binary (http://ant.apache.org/index.html) or source (http://ant.apache.org/srcdownload.cgi) download.
Forsimplicity we shall examine the binary download. Once the Ant ZIP orTAR file has been downloaded (http://antenna.sourceforge.net), its contents should be extracted to a suitable location. Once this has been done,there are a number of environment variables that need to be set, beforeAnt can be used.You will also need to download the antenna-bin-0.9.11.jarand antenna-src-0.9.11.zip files. Place the JAR file in Ant’s libdirectory. Extract the source files to a location under the existing Antinstallation, for example <ant installation>\antenna\ and thenplace the Antenna JAR file in Ant’s lib directory.
This will ensure thatthe Antenna package is in the classpath.Assume, for this example, that Ant is installed in c:\ant\. The followingsets up the environment:set ANT_HOME=c:\antset JAVA_HOME=c:\jdk1.2.2set PATH=%PATH%;%ANT_HOME%\binAlternatively these can be set permanently via the System commandwithin the Control Panel on the PC.Using AntOnce these environment variables have been set up, Ant is ready togo. To run with the default arguments, simply navigate to the directoryINTRODUCTION TO TOOLS FOR MIDP63containing the build.xml file and type ant at the command prompt.As each target is met, its name will be echoed to the screen, so progresscan be monitored.
Any errors will also be written to the screen. Whilebuild.xml is the default build file, different configurations may havebeen created for each project. To specify which build file to use, set the– buildfile argument to identify an alternative file:ant – buildfile <path to build file>Alternatively the developer may only want to run up to a certain targetor perhaps they have a build file containing many targets. This can bespecified by adding the target name as an option. If a particular targethas a dependency (our example hasn’t, but they can be added), then itwill run those first, before running itself.
Executing the emulator may betaken out of the build target in our example, put into a separate targetand executed on its own.ant – buildfile <path to build file> <target name>These are just two useful options. Ant help provides a list of the otheroptions available and it can be called by typing:ant -help2.3.1.3 Nokia Developer’s Suite 2.0 for J2MEOverviewThe Nokia Developer’s Suite 2.0 for J2ME (NDS) has been created byNokia and is available from the Forum Nokia website (download fromthe Tools & SDKs section at www.forum.nokia.com).
It is a tool designedprimarily to enhance existing development tools, although it can runas a standalone tool. Incidentally, there are versions available for bothWindows and Linux platforms.The suite provides developers with class libraries, APIs and Nokiadevice emulators used to create both MIDP 1.0 and MIDP 2.0 Javaapplications. Once it is integrated with an IDE, such as Borland’s JBuilderor Sun’s Studio ONE, it becomes a very useful tool in the development ofmobile applications.The NDS offers many features to the developer:• support for Series 60 MIDP Concept SDK Beta 0.3 Nokia EditionSeries 60 is a major Symbian OS platform, which has been developedby Nokia and licensed to manufacturers such as Sendo, Siemens,Samsung and Panasonic.
This SDK provides a Nokia device referenceimplementation of that platform64GETTING STARTED• deployment on devices using infrared, USB and RS-232 (available onWindows platforms only)The suite provides a convenient interface with which to deploy JARfiles to the device during development.
During testing it is wise tomake intermittent checks on the quality of the application code on thetarget device. This will greatly reduce the frustration and time spent.• FTP uploading capability with WML deck creation• application signing with a public/private key• an integrated audio converter for MIDI and ringtone XML files.For developers new to the Java environment, Figure 2.11 shows howthe NDS can be used to speed up the creation of new classes. Importedpackages and interface references can be set up using a dialog box. Thisalso gives the developer the ability to browse the MIDP packages to findvarious APIs.Figure 2.11Create Class dialog.INTRODUCTION TO TOOLS FOR MIDP65InstallationAlthough the NDS can be installed in standalone mode, it is probably bestused when integrated with an IDE.