JDiet: Java SE 1.4 to Java ME CLDC converter

JDiet Latest Release: here

JDiet is a library of Spoon processors for transforming Java 1.4 programs into Java ME CLDC (Connected Limited Device Configuration) compliant ones.

Java ME CLDC defines a subset of the Java API for applications running on small devices with limited resources such as smartphones. A toolkit, the Sun Java Wireless Toolkit for CLDC (aka WTK), for compiling and running CLDC applications can be downloaded from Sun web site.


Table of contents

  1. About JDiet
  2. Compiling JDiet
  3. Examples

The examples come with a compiled version of JDiet. Developers can then skip Section 2 and proceed directly with Section 3.


About JDiet

JDiet is a library of Spoon processors for transforming Java 1.4 programs into Java ME CLDC (Connected Limited Device Configuration) compliant ones. JDiet removes any Java API call which is not available with the CLDC profile and replaces them with some equivalent versions.

Given a 1.4 compliant source code, JDietProcessor:

  • transforms Set and List into Vector,
  • transforms Map into Hashtable,
  • transforms Iterator into Enumeration,
  • removes usages of serialization related features:
    • java.io.Serializable interfaces,
    • readObject and writeObject methods.

When some semantic adaptation are required, a utility class (see jdiet-runtime) is used. For example, adding an element into a Set is not directly equivalent to adding an element into a Vector (two identical elements can not coexist in a Set). The Helper.addSet method implements such an adaptation. The Helper class is packaged in jdiet-runtime.jar. When running the transformed code, the jdiet-runtime.jar file must be included in the classpath.

Compiling JDiet

JDiet uses the Maven software project management tool. JDiet has been developed with Maven version 2.0.4.

To compile JDiet, from the root directory where JDiet have been installed, type: mvn compile

The name of the JDiet Maven project is spoon-jdiet. spoon-jdiet is divided into two modules:

  • jdiet-core: the core library performing the transformation
  • jdiet-runtime: the runtime library needed to execute a transformed application.

JAR files are generated in the standard maven location (i.e. target/ directories) with mvn package.

Examples

JDiet examples are packaged as a standalone project in jdiet-examples/ with:

  • a ready-to-use build.xml Ant file
  • all software dependencies downloaded in jdiet-examples/lib/
  • all JDiet libraries compiled and stored in jdiet-examples/lib/

The example consists of a program (see jdiet-examples/src/) which uses some Java API which are not supported by CLDC. This program is transformed into a CLDC compliant one by the compilation process.

To launch the transformation, from jdiet-examples/, type: ant

See jdiet-examples/target/spooned for the result of the transformation. This transformed code uses the jdiet-runtime.jar file. This transformed code can then be compiled (the jdiet-examples/target/spooned-classes actually contains the compiled code) and be run on a CLDC compliant VM such as the one provided by the WTK.


Last modified: February 28, 2007 Lionel.Seinturier@lifl.fr