1.把build.xml文件放在你的J2ME工程目录下,修改相关的路径,即可打包.
2.在你的代码中加入如下代码:
//#if polish.Identifier == Nokia/7610
System.out.println("aaaaaaaaa");
//#else
System.out.println("bbbbbbbbbbbb");
//#endif
3.build.xml的详细内容如下:
<project name="PolishTest" default="j2mepolish">
<property file="${user.name}.properties" />
<property name="polish.home" location="D:/java/J2ME-Polish2.0.7" />
<property name="wtk.home" location="D:/java/WTK2.5.2" />
<property file="${polish.home}/global.properties" />
<taskdef name="j2mepolish" classname="de.enough.polish.ant.PolishTask"
classpath="${polish.home}/import/enough-j2mepolish-build.jar:${polish.home}/import/jdom.jar:${polish.home}/import/cldc-1.1.jar:${polish.home}/import/proguard.jar:${polish.home}/yguard-lib.jar:${wtk.home}/wtklib/kenv.zip"/>
<target name="init">
<property name="test" value="false" />
<property name="dir.work" value="build/real" />
<property name="deploy-url" value="" />
<property name="gamename" value="J2MEPolish测试" />
<property name="gamevendor" value="汪力新" />
<property name="jarname" value="PolishTest" />
<property name="midletclass" value="MainMIDlet" />
</target>
<target name="setdeploy" description="Call this target first to set the OTA download-URL, e.g. ant setdeploy j2mepolish">
<property name="deploy-url" value="http://www.company.com/download/" />
</target>
<target name="enableDebug" description="Call this target first to skip the obfuscation step, call the emulator and start the debugger, e.g. ant enableDebug j2mepolish">
<property name="debug" value="true" />
</target>
<target name="test" description="Call this target first to skip the obfuscation step and call the emulator, e.g. ant test j2mepolish">
<property name="test" value="true" />
<property name="dir.work" value="build/test" />
</target>
<!-- In this target the J2ME Polish task is used. -->
<!-- 此任务分3部分: -->
<!-- 1. The info-section 定义一般信息 -->
<!-- 2. The deviceRequirements-section 定义适配的机型 -->
<!-- 3. The build-section 定义build过程 -->
<!-- depends分别为test或者init用于切换是否处于测试阶段. -->
<target name="j2mepolish" depends="init" description="这是build过程的控制部分.">
<j2mepolish>
<info license="GPL" name="${gamename}" version="1.0.0" vendorName="${gamevendor}" icon="/icon.png" jarName="${jarname}_${polish.Name}.jar" copyright="Copyright 2010 ${gamevendor}. All rights reserved."/>
<deviceRequirements >
<requirement name="Identifier" value="Nokia/7610" />
</deviceRequirements>
<build symbols="" usePolishGui="no" workDir="${dir.work}">
<midlet class="${midletclass}" name="${gamename}" number="1"/>
<resources dir="res" defaultexcludes="yes" excludes="readme.txt">
<fileset dir="res" includes="*.*" if="polish.Identifier == Nokia/7210" />
<fileset dir="res" includes="*.*" if="polish.Identifier == Nokia/N-Gage_QD" />
<fileset dir="res" includes="*.*" if="polish.Identifier == Nokia/7260" />
<fileset dir="res" includes="*.*" if="polish.Identifier == Motorola/C650" />
<fileset dir="res" includes="*.*" if="polish.Identifier == Sony-Ericsson/K506" />
<!--
<root dir="resources/base/images" />
<root dir="resources/base/sounds" />
<root dir="resources/customization1" if="cfg.customization1" />
<root dir="resources/customization1/images" if="cfg.customization1" />
<root dir="resources/customization1/sounds" if="cfg.customization1" />
<root dir="resources/customization2" if="cfg.customization2" />
<root dir="resources/customization2/images" if="cfg.customization2" />
<root dir="resources/customization2/sounds" if="cfg.customization2" />
add the localization element for created localized
versions of your application:
<localization>
<locale name="en_US" />
<locale name="de_DE" encoding="utf-8" unless="test" />
</localization>
-->
</resources>
<!--midlet class="MenuMidlet" name="Example" /-->
<!-- project-wide variables - used for preprocessing. -->
<!-- You can set localized variables in the resources/messages.txt files as well. -->
<!-- Here you can set the dir attribute to "resources2" for an alternative design. -->
<!-- obfuscator settings: do not obfuscate when the test-property is true -->
<obfuscator name="ProGuard" useDefaultPackage="false" unless="test" >
<!--You can set additional parameters here, e.g.:
<parameter name="optimize" value="false" />
-->
</obfuscator>
<debug if="test" showLogOnError="true" verbose="true" level="error">
<filter pattern="de.enough.polish.example.*" level="debug" />
<filter pattern="de.enough.polish.ui.*" level="warn" />
</debug>
<jad>
<attribute name="SMS_NUM" value="1065816730107" />
<attribute name="SMS_GAMEID" value="02" />
<attribute name="SMS_CHANNELID" value="07" />
</jad>
</build>
<emulator wait="true" securityDomain="trusted" enableProfiler="true" enableMemoryMonitor="true" enableNetworkMonitor="true" if="debug">
</emulator>
<emulator wait="true" trace="none" securityDomain="trusted" enableProfiler="false" enableMemoryMonitor="false" enableNetworkMonitor="false" if="test and not debug">
</emulator>
</j2mepolish>
</target>
<target name="emulator" depends="test,j2mepolish" description="invokes the emulator">
</target>
<target name="clean" description="allows a clean build. You should call [ant clean] whenever you made changes to devices.xml, vendors.xml or groups.xml">
<delete dir="build" />
<delete dir="dist" includes="**/*" />
</target>
<target name="cleanbuild" description="allows a clean build. You should call [ant cleanbuild] whenever you made changes to devices.xml, vendors.xml or groups.xml" depends="clean, j2mepolish"/>
<target name="debug" description="debugs the project" depends="enableDebug, test, j2mepolish" />
<target name="enableCustomization1">
<property name="dir.work" value="build/customization1" />
<property name="cfg.customization1" value="true" />
</target>
<target name="customization1" description="customizes this project with the settings found in resources/customization1" depends="enableCustomization1, j2mepolish"/>
<target name="enableCustomization2">
<property name="dir.work" value="build/customization2" />
<property name="cfg.customization2" value="true" />
</target>
<target name="customization2" description="customizes this project with the settings found in resources/customization2" depends="enableCustomization2, j2mepolish"/>
</project>