欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用antenna(ant拓展项目)编译、打包j2me程序

程序员文章站 2022-06-22 09:40:19
...
antenna是ant的一个扩展项目,主要封装了j2me的编译打包方法。以下是一个Ant脚本,当中有用到了第三方库:
<?xml version="1.0"?>
<project name="UIdemo" default="build" basedir=".">
	<!-- 属性定义 -->
	<property name="wtk.home" value="E:\programs\sprint wtk"/>
	<property name="wtk.midp.version" value="2.0"/>
	<property name="wtk.cldc.version" value="1.1"/>
	<property name="midlet.name" value="Demo"/>
	<property name="midlet.home" value="."/>
	<property name="app.name" value="手机动漫"/>
	<property name="app.vendor" value="中国移动"/>
	<property name="app.version" value="2.3.0"/>
	
	<!--wtk库-->
	<path id="wtk_path">
		<fileset dir="${wtk.home}\lib">
			<include name="**/*.jar"/>
		</fileset>
	</path>

	<!--第三方库-->
	<path id="external_path">
		<fileset dir="lib">
			<include name="*.jar"/>
		</fileset>
	</path>

	<!-- Define the tasks. -->
	<taskdef name="wtkjad" classname="de.pleumann.antenna.WtkJad"/>
	<taskdef name="wtkbuild" classname="de.pleumann.antenna.WtkBuild"/>
	<taskdef name="wtkpackage" classname="de.pleumann.antenna.WtkPackage"/>
	<taskdef name="wtkmakeprc" classname="de.pleumann.antenna.WtkMakePrc"/>
	<taskdef name="wtkrun" classname="de.pleumann.antenna.WtkRun"/>
	<taskdef name="wtkpreverify" classname="de.pleumann.antenna.WtkPreverify"/>
	<taskdef name="wtkobfuscate" classname="de.pleumann.antenna.WtkObfuscate"/>
	<target name="clean">
		<delete failonerror="false" dir="classes"/>
		<delete failonerror="false">
			<fileset dir=".">
				<exclude name="build.xml"/>
			</fileset>
		</delete>
	</target>
	<target name="build">
		<!-- Creat a new jad -->
		<wtkjad jadfile="${midlet.name}.jad" name="${app.name}" vendor="${app.vendor}" version="${app.version}">
			<midlet name="MIDlet-1" icon="/image/logo1.png" class="com.gaoyang.cartoon.CartoonV2Midlet"/>
		</wtkjad>

		<mkdir dir="classes"/>

		<!-- Compile everything, but don't preverify (yet). -->
		<wtkbuild srcdir="${midlet.home}/src" destdir="classes" preverify="false" encoding="UTF-8" target="1.1">
			<classpath refid="wtk_path"/>
			<classpath refid="external_path"/>
			<compilerarg value="-Xlint:deprecation"/>
		</wtkbuild>

		<!-- Package everything. Most of the necessary information is contained in the JAD file. Also preverify the result this time. To obfuscate everything, set the corresponding parameter to "true" (requires RetroGuard or ProGuard). The version parameter increments the MIDlet-Version by one. -->
		<wtkpackage jarfile="${midlet.name}.jar" jadfile="${midlet.name}.jad">
			<!-- 需要加入jar包的库 -->
			<libclasspath refid="external_path"/>
			<!-- 不需要加入jar包的库(wtk库)-->
			<classpath refid="wtk_path"/>
			<!-- Package our newly compiled classes and the resources from the WTK's demo application. -->
			<fileset dir="classes"/>
			<fileset dir="${midlet.home}/res"/>
		</wtkpackage>
		<wtkobfuscate jarfile="${midlet.name}.jar" jadfile="${midlet.name}.jad">
			<classpath refid="wtk_path"/>
			<argument value="'-keep public class * extends javax.microedition.midlet.MIDlet'"/>
			<argument value="-dontusemixedcaseclassnames"/>
			<argument value="-microedition "/>
			<argument value="-dontnote"/>
			<argument value="-dontwarn"/>
			<argument value="-defaultpackage ''"/>
		</wtkobfuscate>
	</target>
</project>


注意:
1、环境变量classpath中要加入antenna jar包的引用
2、打包时第三方库文件要加入jar包,而wtk则不用
3、不要在打包时添加参数obfuscate="true"直接混淆,这样可能无法加入参数,要单独混淆


Antenna项目网址:http://antenna.sourceforge.net/