From: W. Trevor King Date: Fri, 31 Dec 2010 16:27:08 +0000 (-0500) Subject: Add Java_ME post. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4ec2154f965218466ab6037edeb4a942119dfcac;p=mw2txt.git Add Java_ME post. --- diff --git a/posts/Java_ME.mdwn b/posts/Java_ME.mdwn new file mode 100644 index 0000000..e1bc340 --- /dev/null +++ b/posts/Java_ME.mdwn @@ -0,0 +1,80 @@ +[[!meta title="Java Micro Edition"]] + +Many cell phones and similar devices run a constrained version of the +Java Virtual Machine (JVM) called the Sun Java Wireless Toolkit CLDC , +Java 2 Micro Edition, or something similar (Sun/Oracle seem to like +changing package names). If you want to write a MIDlet that runs on +your phone, take a look at Vikram Goyal's detailed [tutorial][VG] +(note: Windows-based commands, but they translate easily into Linux +equivalents). + +After installing a J2ME SDK (see below) I worked through the examples +in Vikram's tutorial and those in a [post by Hexist][Hexist], to +compile a simple app. Here's the source for the app with a cleaned up +`Makefile`: + +* [[Makefile]] +* [[HelloWorld.java]] +* [[Manifest]] +* [[!ltio icon.png]] + +It's a bit annoying getting a J2ME SDK set up on Linux, because the +[Java Wireless Toolkit][WTK] requires the old and buggy Java 1.5. On +my Gentoo box, I had to mask version of the JDK greater than 1.5 by +creating `/etc/portage/package.mask/java_wtk` containing the line + + >=virtual/jdk-1.6 + +The Gentoo Portage tree no longer carries Java 1.5 ebuilds, so I +installed the Java overlay + + # layman -a java-onverlay + +I then started trying to emerge the JDK with calls to + + # emerge -av virtual/jdk + +In order for that to succeed I had to: + +* Create `/etc/portage/package.keywords/java_wtk` containing + `dev-java/sun-jdk ~x86` to unmask the JDK. +* Create `/etc/portage/package.use/java_wtk` containing + `dev-java/sun-jdk -doc` to avoid a fetch restriction on the + documentation. +* Add `ACCEPT_LICENSE="dlj-1.1"` to `/etc/make.conf` to accept + Sun's license for Java 1.5. + +Take a look at the [Gentoo Java Guide][GJG] page for general +information on running Java on Gentoo. + +Once I got the JDK installed, I installed the [Wireless Toolkit][WTK] +in `~/lib/WTK2.5.2` using + + $ equery files sun-jdk | grep /bin/javac + +to identify `/opt/sun-jdk-1.5.0.22/` as the Java SDK path. + +Anyhow, after getting all that setup, I learned that my +[Verizon-provided Casio C721][C721] is running the ancient [BREW][] OS +3.x (Chris Wright's [history of mobile games][history] says that BREW +went commercial in 2002, but doesn't list specific version release +dates). To top that off, they charge [$400 for a developer +signature][sig] needed to install apps on *your own phone*. + +There is an outside chance that they are getting their act together +though, with vague press releases about [upgrading][] to [Brew MP][] +and [lowering the barrier to entry for app-delivery][open]. I'm +skeptical, but I suppose time will tell. + +[JGl]: http://today.java.net/pub/a/today/2005/02/09/j2me1.html +[Hexist]: http://hexist.com/?p=29 +[GJG]: http://www.gentoo.org/doc/en/java.xml +[WTK]: http://www.oracle.com/technetwork/java/download-135801.html +[C721]: http://developer.verizon.com/jsps/devCenters/DeviceDB/Landing_Pages/BewCasioExilim.jsp +[BREW]: http://en.wikipedia.org/wiki/Binary_Runtime_Environment_for_Wireless +[history]: http://www.pocketgamer.biz/r/PG.Biz/A+Brief+History+of+Mobile+Games/feature.asp?c=10618 +[sig]: http://en.wikipedia.org/wiki/Binary_Runtime_Environment_for_Wireless#Development_fees +[upgrade]: http://www.brewmp.com/showcase/verizon-wireless +[Brew MP]: http://www.brewmp.com/ +[open]: http://news.vzw.com/news/2010/07/pr2010-06-29.html +[WAP]: http://en.wikipedia.org/wiki/Wireless_Application_Protocol diff --git a/posts/Java_ME/HelloWorld.java b/posts/Java_ME/HelloWorld.java new file mode 100644 index 0000000..802c987 --- /dev/null +++ b/posts/Java_ME/HelloWorld.java @@ -0,0 +1,18 @@ +import java.util.Date; + +import javax.microedition.lcdui.Alert; +import javax.microedition.lcdui.Display; +import javax.microedition.midlet.MIDlet; + +public class HelloWorld extends MIDlet { + Alert timeAlert; + public HelloWorld() { + timeAlert = new Alert("Alert!"); + timeAlert.setString("Hello World! The time is now " + new Date().toString()); + } + public void startApp() { + Display.getDisplay(this).setCurrent(timeAlert); + } + public void pauseApp() { } + public void destroyApp(boolean unconditional) { } +} diff --git a/posts/Java_ME/Makefile b/posts/Java_ME/Makefile new file mode 100644 index 0000000..6743e53 --- /dev/null +++ b/posts/Java_ME/Makefile @@ -0,0 +1,64 @@ +# Modify these appropriately for your Java installation + +JDK_BASE = /usr +J2ME_BASE = $(HOME)/lib/WTK2.5.2 + +# Modifiy these appropriately for your project + +NAME = HelloWorld # should also be the name of your MIDlet subclass +SRC = HelloWorld.java +OTHER = Manifest icon.png + +# Paths to standard system programs + +ECHO = echo +MKDIR = mkdir +STAT = stat +RM = rm +UNZIP = unzip + +# Paths to Java-specific programs + +JAVAC = $(JDK_BASE)/bin/javac +JAR = $(JDK_BASE)/bin/jar +EMULATOR = $(J2ME_BASE)/bin/emulator +PREVERIFY = $(J2ME_BASE)/bin/preverify + +# Options passed to Java-specific programs + +CLASSPATH = "$(J2ME_BASE)/lib/midpapi20.jar:$(J2ME_BASE)/lib/cldcapi10.jar" +JAVA_CFLAGS = -bootclasspath $(CLASSPATH) -target 1.3 -source 1.3 \ + -d compiled -classpath compiled -sourcepath . -g +PREVERIFY_CLASSPATH = $(CLASSPATH) + + +all: $(NAME:%=%.jar) $(NAME:%=$.jad) + +run: $(NAME:%=%.jad) + $(EMULATOR) -Xdescriptor:$< + +compiled: + $(MKDIR) -p compiled + +verified: + $(MKDIR) -p verified + +compiled/%.class: %.java compiled + $(JAVAC) $(JAVA_CFLAGS) $< + +verified/%.class: compiled/%.class verified + $(PREVERIFY) -classpath $(PREVERIFY_CLASSPATH):compiled -d verified $(NAME) + +$(NAME:%=%.jar): $(OTHER) $(SRC:%.java=verified/%.class) + $(JAR) cfm $@ $(OTHER) -C verified $(SRC:%.java=%.class) + +%.jad: %.jar + $(UNZIP) -aa -j -p $< "META-INF/MANIFEST.MF" > $@ + $(ECHO) "MIDlet-Jar-URL: $<" >> $@ + $(ECHO) "MIDlet-Jar-Size: " $(shell $(STAT) -c%s $<) >> $@ + +clean: + rm -rf compiled verified + rm -f *.jar *.jad + +.PHONY: clean all run diff --git a/posts/Java_ME/Manifest b/posts/Java_ME/Manifest new file mode 100644 index 0000000..5764611 --- /dev/null +++ b/posts/Java_ME/Manifest @@ -0,0 +1,8 @@ +MIDlet-Name: HelloWorld +MIDlet-Vendor: YourName +MIDlet-Version: 1.0 +MIDlet-Icon: /icon.png +MIDlet-Info-URL: http://example.com/your/homepage +MicroEdition-Configuration: CLDC-1.0 +MicroEdition-Profile: MIDP-2.0 +MIDlet-1: HelloWorld, /icon.png, HelloWorld diff --git a/posts/Java_ME/icon.png b/posts/Java_ME/icon.png new file mode 100644 index 0000000..bb1dba6 Binary files /dev/null and b/posts/Java_ME/icon.png differ