出家如初,成佛有余

Funambol Syncml J2ME版本客户端编译指南

Posted in Uncategorized by chuanliang on 2008/06/05

简单描述一下安装测试funambol j2me客户端过程,过程只是用于测试j2me客户端功能,并没有考虑完整的项目应用,供参考备查。

1. 安装ant

从http://apache.mirror.phpchina.com/ant/binaries/apache-ant-1.7.0-bin.zip下载ant

解压到c:ant下

2. 安装antenna

从http://downloads.sourceforge.net/antenna/antenna-bin-1.0.2.jar下载antenna

拷贝到c:antlib

3. 安装wtk

从http://cds-esd.sun.com/ESD36/JSCDL/sun_java_wireless_toolkit/2.5.2/sun_java_wireless_toolkit-2_5_2-windows.exe?AuthParam=1212392225_9f66723e80a5d5619add0637b1c54f9b&TicketId=B%2Fw5kByCTl9JSBVLP1dSlQHm&GroupName=CDS&FilePath=/ESD36/JSCDL/sun_java_wireless_toolkit/2.5.2/sun_java_wireless_toolkit-2_5_2-windows.exe

下载wkt并安装到c:WTK2.5.2

4. 下载JMUnit

从http://jaist.dl.sourceforge.net/sourceforge/jmunit/JMUnit_1.0.1.zip下载JMUnit

解压后拷贝到C:WTK2.5.2bin及C:WTK2.5.2lib下

5. 在Eclipse中安装EclipseME

6. 从objectweb的cvs库获取funambol的j2me包

可以从http://download.forge.objectweb.org/sync4j/funambol-j2me-api-6.5.10.zip下载现成的funambol的j2me包

为了开发方便,从cvs库检出代码,自己编译

cvs库的信息:

认证方式:pserver

主机地址:cvs.forge.objectweb.org

用户名:anonymous

CVSROOT:anonymous@cvs.forge.objectweb.org:/cvsroot/sync4j

检出/funambol/client-api/j2me下的文件

7. 编译common包

7.1. 新建funambol-j2me-common项目

在eclipse中新建一个叫funambol-j2me-common的J2ME Midlet Suite项目,导入/funambol/client-api/j2me/common下的文件

由于没有安装BlackBerry的SDK,因此删除如下文件:

src/com/funambol/storage/BlackberryRecordStore.java

src/com/funambol/storage/BlackberryRecordEnumeration.java

src/com/funambol/util/BlackberryHelper.java

7.2. 修改build.properties

#

# Funambol J2ME API build properties file

#

j2me.name=funambol-j2me-common

j2me.release.major=7

j2me.release.minor=0

j2me.build.number=0

# Set this to your WTK installation, or copy the JAR to the local /lib

wtk.home=C:/WTK2.5.2

wtk.debug=false

# Set this to your JMunit installation, or copy the JAR to the local /lib

lib.junit=C:/WTK2.5.2/lib/JMUnit4CLDC10.jar

# Set this to your JZlib jar file, or copy the JAR to the local /lib

#lib.jzlib=lib/jzlib-1-0-7a.jar

lib.gzip=lib/tinyline-gzip.jar

7.3. 用ant运行build.xml

注意确保把antenna添加到ant的Classpath中,不采用eclipse自身的Ant Home

Run As ->Open External Tools Dialog->Ant Build->funambol-j2me-common->Classpath->Ant Home

7.4. 用EclipseME的工具创建package,以方便funambol-j2me-syncml项目编译使用

Right Button->J2ME->Create Package

生成的打包文件funambol-j2me-common.jar及funambol-j2me-common.jad存放在deployed目录下

8. 编译syncml包

8.1. 新建funambol-j2me-syncml项目

在eclipse中新建一个叫funambol-j2me-syncml的J2ME Midlet Suite项目,导入/funambol/client-api/j2me/syncml下的文件,再在funambol-j2me-syncml创建lib目录

8.2. 拷贝funambol-j2me-common文件

把funambol-j2me-common deploy目录下funambol-j2me-common.jar的文件拷贝到unambol-j2me-syncml的lib目录下

把funambol-j2me-common编译目录(假定为bin)下的文件拷贝到funambol-j2me-syncml的编译目录(假定为bin)下

8.3. 修改build.properties

#

# Funambol J2ME API build properties file

#

j2me.name=funambol-j2me-syncml

j2me.release.major=7

j2me.release.minor=0

j2me.build.number=0

# Set this to your WTK installation, or copy the JAR to the local /lib

wtk.home=C:/wtk2.5.2

wtk.debug=false

# Set this to your JMunit installation, or copy the JAR to the local /lib

lib.junit=C:/WTK2.5.2/lib/JMUnit4CLDC10.jar

# Uncomment this to refer to the output lib of your ‘common’ module, or copy

# the JAR to the local /lib

lib.funambol.common=${basedir}/lib/funambol-j2me-common.jar

8.4. 修改build.xml

将 <target name=”preprocess” depends=”init”>

<mkdir dir=”${dir.preproc.src}”/>

<wtkpreprocess srcdir=”${dir.src}”

destdir=”${dir.preproc.src}”

symbols=”${device.isBlackberry_plugin}”

verbose=”false” indent=”false”>

</wtkpreprocess>

</target>

修改为

<target name=”preprocess” depends=”init”>

<mkdir dir=”${dir.preproc.src}”/>

<wtkpreprocess srcdir=”${dir.src}”

destdir=”${dir.preproc.src}”

verbose=”false” indent=”false”>

</wtkpreprocess>

</target>

实际上就是删除symbols=”${device.isBlackberry_plugin}”

8.5. 在test目录下编写测试用的Midelet SyncMidlet.java

package com.funambol.syncml.client;

import java.util.Random;

import javax.microedition.lcdui.Display;

import javax.microedition.lcdui.TextBox;

import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;

import com.funambol.syncml.protocol.SyncML;

import com.funambol.syncml.spds.SourceConfig;

import com.funambol.syncml.spds.SyncConfig;

import com.funambol.syncml.spds.SyncManager;

import com.funambol.syncml.spds.SyncSource;

import com.funambol.util.Log;

public class SyncMidlet extends MIDlet {

private static final String STORE_NAME = “TESTCONFIG”;

private static final String SOURCE_NAME = “source.briefcase”;

private static final String URL = “http://localhost:8080/funambol/ds&#8221;;

private static final String userName=”liangchuan”;

private static final String password=”liangchuan”;

private Display display;

private TextBox t;

private SourceConfig sc;

private SyncConfig conf;

private SyncManager sm;

private TestSyncSource testsrc;

private TestSyncListener sl ;

public SyncMidlet() {

display = Display.getDisplay(this);

t = new TextBox(“Syncml Test MIDlet”, “Syncml Test MIDP!”, 256, 0);

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

protected void pauseApp() {

display.setCurrent(t);

}

protected void startApp() throws MIDletStateChangeException {

sc = new SourceConfig();

conf = new SyncConfig();

conf.syncUrl = URL;

conf.userName =userName;

conf.password =password;

conf.deviceConfig.devID = generateDeviceId();

sc.setType(“text/plain”);

sc.setEncoding(SyncSource.ENCODING_NONE);

sm = new SyncManager(conf);

testsrc = new TestSyncSource(sc);

sl = new TestSyncListener();

testsrc.setListener(sl);

sm.sync(testsrc, SyncML.ALERT_CODE_SLOW);

display.setCurrent(t);

}

public String generateDeviceId() {

Random r = new Random();

StringBuffer s = new StringBuffer(“fsc-j2me-api-test-“);

s.append(Long.toString(System.currentTimeMillis(),16));

s.append(Integer.toHexString(r.nextInt()));

String deviceId = s.toString();

return deviceId;

}

}

8.6. 用ant运行build.xml的build[default]、compile、compiletest target

注意确保把antenna添加到ant的Classpath中,不采用eclipse自身的Ant Home

Run As ->Open External Tools Dialog->Ant Build->funambol-j2me-syncml->Classpath->Ant Home

8.7. 拷贝funambol-j2me-common classes文件用于打包

把funambol-j2me-common output/classses下的文件拷贝到funambol-j2me-syncml的编译目录(假定为bin)下

8.8. 拷贝funambol-j2me-syncml项目的文件用于打包

把funambol-j2me-syncml用ant编译目录out/classes下的文件拷贝到funambol-j2me-syncml的编译目录(假定为bin)下

8.9. 用EclipseME的工具创建package

Right Button->J2ME->Create Package

生成的打包文件funambol-j2me-syncml.jar及funambol-j2me-syncml.jad存放在deployed目录下

8.10. 修改funambol-j2me-syncml.jad

双击funambol-j2me-syncml.jad,在Midlets标签中增加MIDlet-
1描述如下内容:

Name :SyncMidlet

Icon:无

Class:com.funambol.syncml.client.SyncMidlet

或者直接修改funambol-j2me-syncml.jad,增加

MIDlet-1: SyncMidlet,,com.funambol.syncml.client.SyncMidlet

8.11. 通过WTK测试的Run MIDP Application运行SyncMidlet

8.12. 使用EclipseME打包注意事项:

在用eclipseme打包时候,好像很不稳定,有时候不能把所有的文件打进包中,解决办法:

用手工把funambol-j2me-syncml/bin下的类文件(包括funambol-j2me-common的类)通过jar或winrar打入eclipseme生成的jar包中,同时手工编辑生成funambol-j2me-syncml.jad,修改MIDlet-Jar-Size,其中MIDlet-Jar-Size大小看funambol-j2me-syncml.jar文件属性得到

MIDlet-Jar-Size: 115491

MIDlet-Jar-URL: funambol-j2me-syncml.jar

MIDlet-Name: funambol-j2me-syncml Midlet Suite

MIDlet-Vendor: Midlet Suite Vendor

MIDlet-Version: 1.0.8

MicroEdition-Configuration: CLDC-1.1

MicroEdition-Profile: MIDP-2.0

MIDlet-Name: synctest Midlet Suite

MIDlet-1: SyncMidlet,,com.funambol.syncml.client.SyncMidlet