Enterprise J2ME Developing Mobile Java Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Enterprise J2ME Developing Mobile Java Applications [Electronic resources] - نسخه متنی

Michael Juntao Yuan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



A.5 Packaging and Building


We can compile MIDP applications using the normal JDK compiler with the MIDP core classes in the boot classpath. Due to MIDP's lightweight class verification schemes, we have to pre-verify MIDP classes before deploying them. The Sun J2ME Wireless ToolKit and vendor MIDP kits provide preverify utilities for many platforms. Those utilities take in compiled MIDP classes and output pre-verified ones.

Since the AMS cannot take classpath, all MIDP applications must be completely self-contained with all necessary third-party libraries. We can pack all pre-verified application and library classes and all necessary images and other static resource files into the JAR file. The JAR file must contain a manifest file (Listing A.2) that conforms to the MIDP specification.

Listing A.2. The JAR manifest file



Manifest-Version: 1.0
MIDlet-1: Demo, ,com.enterprisej2me.simpledemo.DemoMIDlet
MIDlet-Name: Demo
MIDlet-Version: 1.0.0
MIDlet-Vendor: Michael Yuan
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0

The AMS reads a Java Application Descriptor (JAD) file (Listing A.3) to locate the MIDP JAR file and class names of the MIDlets. The AMS file can also contain custom properties the AMS can pass to the MIDlets at runtime.

Listing A.3. The JAD file



Manifest-Version: 1.0
MIDlet-1: Demo, ,com.enterprisej2me.simpledemo.DemoMIDlet
MIDlet-Name: Demo
MIDlet-Version: 1.0.0
MIDlet-Jar-Size: 44405
MIDlet-Jar-URL: SimpleDemo.jar
MIDlet-Vendor: Michael Yuan
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
MIDlet-Install-Notify: http://127.0.0.1:8080/midp/servlet/feedback
MIDlet-Permissions: javax.microedition.io.HttpConnection

The build process is illustrated in the ANT script (Listing A.4). The corresponding project directory structure is illustrated in Figure A.2.


Figure A.2. The project directory structure.


Listing A.4. The ANT build script


<project name="SimpleDemo" default="all">
<target name="init">
<tstamp/>
<property name="projname" value="SimpleDemo" />
<property name="WTK" value="C:/Java/WTK20" />
<property name="midpclasses" value="${WTK}/lib/midpapi.zip" />
<property name="preverify" value="${WTK}/bin/preverify" />
<property name="emulator" value="${WTK}/bin/emulator" />
<property name="tmp" value="anttmp" />
<property name="tmpclasses" value="${tmp}/tmpclasses" />
<property name="pvclasses" value="${tmp}/pvclasses" />
</target>
<target name="clean" depends="init">
<delete dir="${tmp}" />
<delete file="bin/${projname}.jar" />
<delete file="bin/*.sh" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${tmp}" />
<mkdir dir="${tmpclasses}" />
<mkdir dir="${pvclasses}" />
<unzip dest="${tmpclasses}">
<fileset dir="lib">
<include name="**/*.zip"/>
<include name="**/*.jar"/>
</fileset>
</unzip>
<delete dir="${tmpclasses}/META-INF" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="src" destdir="${tmpclasses}"
bootclasspath="${midpclasses}"
>
<classpath>
<pathelement path="${tmpclasses}"/>
<pathelement path="${midpclasses}"/>
</classpath>
</javac>
</target>
<target name="preverify" depends="compile">
<exec executable="${preverify}">
<arg line="-classpath ${midpclasses}"/>
<arg line="-d ${pvclasses}" />
<arg line="${tmpclasses}" />
</exec>
</target>
<target name="package" depends="preverify">
<copy todir="${pvclasses}">
<fileset dir="res" />
</copy>
<jar jarfile="bin/${projname}.jar"
basedir="${pvclasses}"
manifest="bin/MANIFEST.MF"
/>
</target>
<target name="run" depends="init" >
<exec executable="${emulator}" dir="bin">
<arg line="-classpath ${projname}.jar" />
<arg line="-Xdescriptor:${projname}.jad" />
</exec>
</target>
<target name="all" depends="package" />
</project>


/ 204