Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's been a while since I asked this question, and I while since I found a nice, working solution for the problem, but I had since forgotton to tell you.</p> <p>My main focus was the Java Collections Framework, which is part of the <code>java.util</code> package.</p> <p>I've finally taken the source code of Suns Java 6.0 and copied all the classes that belong to the Collections framework into a project of my own. This was a Java 6.0 project, but I used the jars from J2ME as classpath. Most of those classes that I copied depend on other J2SE classes, so there are broken dependencies. Anyway, it was quite easy to cut those depensencies by leaving out everything that deals with serialization (which is not a priority for me) and some minor adjustments.</p> <p>I compiled the whole thing with a Java 6 compiler, and retrotranslator was used to port the resulting bytecode back to Java 1.2.</p> <p>Next problem is the package name, because you can't deliver classes from <code>java.util</code> with a J2ME application and load them - the bootstrap class loader won't look into the applications jar file, the other bootloaders aren't allowed to load something with that package name, and on J2ME you can't define custom classloaders. Retrotranslator not only converts bytecode, it also helps to change name references in existing bytecode. I had to move and rename all classes in my project, e.g. <code>java.util.TreeMap</code> became <code>my.company.backport.java.util.TreeMap_</code>.</p> <p>I was than able to write actual J2ME application in a second Java 6.0 project which referenced the usual <code>java.util.TreeMap</code>, using the generic syntax to create type-safe collections, compile that app to Java 6.0 byte code, and run it through retrotranslator to create Java 1.2 code that now references <code>my.company.backport.java.util.TreeMap_</code>. Note that <code>TreeMap</code> is just an example, it actually works for the whole collections framework and even for 3rd party J2SE Jars that reference that framework.</p> <p>The resulting app can be packaged as a jar and jad file, and runs fine on both J2ME emulators and actual devices (tested on a Sony Ericsson W880i).</p> <p>The whole process seems rather complex, but since I used Ant for build automation, and I needed retranslator anyway, there only was a one-time overhead to setup the collection framework backport.</p> <p>As stated above, I've done this nearly a year ago, and writing this mostly from the top of my head, so I hope there are no errors in it. If you are interested in more details, leave me a comment. I've got a few pages of German documentation about that process, which I could provide if there is any demand.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload