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:
- 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).
- When standard libraries don't have maven plugins don't despair. You can:
- 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.
- just interface with the ant taskdef, or straight to the library yourself using groovy. Do this if it's a one off.
- 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.
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
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
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.
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
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'm getting there.
working on 'plat-default' now.