Tuesday, June 27, 2006

 

J2ME and Maven2 solved!

After much much too much head scratching I have discovered 'the way' to develop with maven in general. Maybe I'll write up a little more in depth description of 'the way' later, but for now a summary:

  1. Maven needs a scripting language. Enter groovy. Groovy rocks. If you wanna migrate some ant scripts or take advantage of ant taskdefs for some specific library, then groovy is the way to do it. Although maven2 has an Ant plugin to run arbitrary ant code, it is in essence useless for all but the simplest tasks (Unfortunately I discovered that the groovy-maven-plugin is slightly broken. You can't use the AntBuilder out of the box. Worry not, there is a workaround. See http://jira.codehaus.org/browse/MOJO-429 for more information).
  2. When standard libraries don't have maven plugins don't despair. You can:
    1. write your own. It's really easy. I advice writing it in Java, not Ant. Do this if you want glory or expect to use it more than once.
    2. just interface with the ant taskdef, or straight to the library yourself using groovy. Do this if it's a one off.
  3. Probably the biggest problem when starting with maven is that a library you need isn't in the public repository. Use Maven - Guide to installing 3rd party JARs


Back to getting that J2MEPolish example running. Again, I was missing a dependency:

mvn install:install-file -Dfile=blackberry-4.0.jar -DgroupId=j2mepolish -DartifactId=blackberry -Dversion=4.0 -Dpackaging=jar


I fixed my groovy-maven-plugin by adding the Ant dependency to the groovy-maven-plugin pom.xml. I could then use the AntBuilder. I have to say I was skeptical at first, but once I got started, wow!

Rather than writing a maven plugin for proguard (yes there should be one, no I'm not writing it to get an example application running), it was simply a matter of using the Ant taskdef from within groovy. Here is my groovy script:

import groovy.util

def libraryjars = ""
def ant = new AntBuilder()

for (dep in project.artifacts) {
if (dep.artifactId =~ /enough-client/) j2medep = dep
else if (dep.artifactId =~ /proguard/) {
proguard = dep
ant.taskdef(name:"proguard",classname:"proguard.ant.ProGuardTask",classpath:dep.file)
}
else {
libraryjars += "\n-libraryjar ${dep.file}"
}
}

def configuration = "-injars target/classes"+
"\n-injars ${j2medep.file}"+
"\n-outjars target/proguard.jar"+
"\n${libraryjars}"+
"\n-overloadaggressively"+
"\n-ignorewarnings"+
"\n-defaultpackage ''"+
"\n-allowaccessmodification"+
"\n-dontobfuscate"+
"\n-keep public class com.grimo.me.product.midpsysinfo.MIDPSysInfoMIDlet"

println "executing proguard for:\n ${configuration}"

ant.proguard(configuration)
ant.move(file:"target/classes",tofile:"target/oldclasses")
ant.unzip(src:"target/proguard.jar",dest:"target/classes")

This weaved together underlying dependencies, preverified, and made the jad. I then used the mpowerplayer to run the app. It had a little issue with localization, but apart from that the app really ran. Wow, that took a week of odd hours.

Blogged with Flock


Wednesday, June 21, 2006

 

Proguard investigations.

Rather than integrating proguard directly in maven2, I decided to follow the directions over at the proguard site to integrate it into the WTK.

Hmm, but that didn't do anything. I think maybe that only works if you use something in the wtk folder to build the project. Darn.

There is a plugin for proguard out there. I guess I'll have to look it up. Didn't find one, I've submitted a question to the proguard mailing list to see what I can find out. I think I'm gonna have to write my own.

 

Skip J2MEPolish - lets just fiddle with J2ME

Making some progress here. After I got the java files to compile, the next step is to have the WTK preverify my compiled classes. Someone, Frank Seidinger bless his soul, has created a maven plugin for j2me. It'll do the preverify and the jad creation. It's currently in the codehaus sandbox, so you have to surf through the subversion repository, check it out, and compile it yourself if you want to use it.

I found out I was still missing something - the j2me java.lang.Object! Oops:

mvn install:install-file -Dfile=/WTK2.2/lib/cldcapi10.jar -DgroupId=javax.microedition -DartifactId=cldc -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=/Users/danesummers/Documents/WTK2.2/lib/cldcapi11.jar -DgroupId=javax.microedition -DartifactId=cldc -Dversion=1.1 -Dpackaging=jar

It preverifies with cldc 1.0.

I can even get it to generate the jar files...but there is a slight problem. Since this is a j2mepolish example, well, there are some j2mepolish requirements...and those aren't in my jar file. How do I make them go in?

 

Twiddling with J2MEPolish

The samples don't work out of the box for J2MePolish, because wtk2.2 isn't for osx (linux). I copied the preverify app from mpowerplayer over wtk2.2's - now the samples compile! I can use the mpowerplayer application to run the j2me sample application. Sweet.

Now...maven? I copied over one of the sample application from J2MEPolish into a stock maven2 project.

I got some of the sources to compile by adding in the WTK libraries one at a time. So far I've only added a few jars for WTK:

mvn install:install-file -Dfile=~/WTK2.2/lib/midpapi10.jar -DgroupId=javax.microedition -DartifactId=midp -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=~/WTK2.2/lib/midpapi20.jar -DgroupId=javax.microedition -DartifactId=midp -Dversion=2.0 -Dpackaging=jar
mvn install:install-file -Dfile=/Users/danesummers/Documents/WTK2.2/lib/mmapi.jar -DgroupId=javax.microedition -DartifactId=mmapi -Dversion=1.0 -Dpackaging=jar

And a few more jars for J2MEPolish:

mvn install:install-file -Dfile=/Users/danesummers/Documents/J2MEPolish/import/enough-j2mepolish-client.jar -DgroupId=j2mepolish -DartifactId=enough-client -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=/Users/danesummers/Documents/J2MEPolish/import/nokia-ui.jar -DgroupId=nokia -DartifactId=ui -Dversion=1.0 -Dpackaging=jar

And here are the dependencies:



<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.microedition</groupId>
<artifactId>midp</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>nokia</groupId>
<artifactId>ui</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.microedition</groupId>
<artifactId>mmapi</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>j2mepolish</groupId>
<artifactId>enough-client</artifactId>
<version>1.0</version>
</dependency>
</dependencies>


Hey it actually compiles in maven. Thats a start I guess.

Wednesday, June 14, 2006

 

Starting j2me port.

I remember that last year a friend of mine tried to start doing j2me work on OSX, and he had a lot of trouble. Sun doesn't provide an OSX package of the WTK, or any emulator. You gotta cobble together the thing yourself. So far I've gotten thus far:

1. Using the linux installer for WTK2.2 install the WTK.
2. Install j2mepolish
3. install mpowerplayer

Remaining items to scratch my head on:

1. Do I need to use J2MEUnit?
2. How am I going to integrate the wtk and building into my maven2 project?

Thursday, June 08, 2006

 

Site Temporarily Back Up

The website is still down, but in the meantime, I've setup the installer so that people can at least install their desktop tool.

Hopefully I'll get those repository dumps by the weekend so I can put up the real site and start making a few sales!

Well, we'll see.

Saturday, June 03, 2006

 

still refactoring

I figured out that the layout of my test cases wasn't quite right - I have a couple subprojects that are sort of abstract, with a couple of conrete implementation subprojects after that. The problem was that a lot of the concrete tests were excersizing code in the abstract base subproject. Those tests should ahve been in the base project.

I'm getting there.

working on 'plat-default' now.

This page is powered by Blogger. Isn't yours?