Thursday, April 22, 2010

Maven j2me-Archetype

I am using Netbeans6.7 for mobile project development and want to make that project a 'maven project'. I have maven configured on my machine.

To make maven based j2me project I have created a new project from File > New Project > Maven > Maven Project > j2me Archetype (2.0.4). The project created successfully and showing the properties of maven as well . . .  BUT !!

I cannot able to view the properties of mobile project (i.e. Platform Type, Device Profile and Configuration, Midlet Information etc). To execute that project it requires a class with main() method. So I have posted all that on forum and finally got the following answer:

j2me development is not supported for maven projects in netbeans :(


Thursday, April 15, 2010

JSON source for J2ME (mobile applications)

Javascript Object Notation (JSON) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. I am trying to use it in for mobile application development.

Today I was looking for a JSON source code for Java Micro Edition (J2ME). After lots of googling I have found it from the following link:


Wednesday, April 7, 2010

Share Common Code Between J2ME and J2SE Project -- Problem/Solution


If you are creating a client/server project on Java, where client is a mobile device and server is a web application. Also if there is a common code between client and server then where do you place that common code ?

I also faces the same and go through the following phases before deciding what to do. The two points that came in mind right away are:

  • Create a J2SE Project and place common code there. Make your client and server project dependant on that common project.
  • Create a J2ME Project and place common code there. Make your client and server project dependant on that common project.

First I have created J2SE as a Common Project:

When I execute the client (J2ME) project with a dependency of common project (J2SE), I got the following error:

Running with storage root DefaultColorPhone
Method............: 100d2aa8 'com/sun/midp/midlet/MIDletState.createMIDlet (stat
Stack Chunk.......: e58cd4
Frame Pointer.....: e58d30
Current IP........: 10128592 = 10128584 + offset 14
Previous Frame....: e58cf4
Previous IP.......: 1012052b (offset 22)
Frame size........: 8 (1 arguments, 7 local variables)
Argument[0].......: e59a9c
Local[1]..........: 0
Local[2]..........: e58cf4
Local[3]..........: e68858
Local[4]..........: e58d08
Local[5]..........: 100dcdd0
Local[6]..........: e58cd4
Local[7]..........: 1015f0a0
Operand[1]........: e59a9c

Method............: 100cd0e4 'com/sun/midp/midlet/ (virtual)'
Stack Chunk.......: e58cd4
Frame Pointer.....: e58cf4
Current IP........: 1012052b = 10120515 + offset 22
Previous Frame....: 0
Previous IP.......: 1
Frame size........: 6 (1 arguments, 5 local variables)
Argument[0].......: e59d10
Local[1]..........: e68a68
Local[2]..........: e59a9c
Local[3]..........: 0
Local[4]..........: 0
Local[5]..........: 0
Operand[1]........: e68a68

VM status:
Instruction pointer.: 10128592 (offset within invoking method: 14)
Next instruction....: 0x4c
Frame pointer.......: e58d30
Local pointer.......: e58d10
Stack size..........: 128; sp: e58d48; ranges: e58cdc-e58edc;
Contents of the current stack frame:
e58d10: e59a9c (lp)
e58d14: 0
e58d18: e58cf4
e58d1c: e68858
e58d20: e58d08
e58d24: 100dcdd0
e58d28: e58cd4
e58d2c: 1015f0a0
e58d30: e58cf4 (fp)
e58d34: 1012052b
e58d38: e58d0c
e58d3c: 100d2aa8
e58d40: e58cd4
e58d44: 0 (end of frame)
e58d48: e59a9c (sp)
Execution stack contains 112 items:

Execution completed.
429584 bytecodes executed
10 thread switches
486 classes in the system (including system classes)
2380 dynamic objects allocated (72064 bytes)
1 garbage collections (0 bytes collected)
ALERT: java/lang/ClassFormatError: Bad version information.
Execution completed.
429584 bytecodes executed
10 thread switches
486 classes in the system (including system classes)
2380 dynamic objects allocated (72064 bytes)
1 garbage collections (0 bytes collected)

After reading some forums I recompile my common project (J2SE) on jdk1.4 and add it as a dependency in client project (J2ME) again (previously I have compiled it on jdk1.5). This time the client (J2ME) executes and works successfully.


In Java the development toolkit for mobile (J2ME) contains limited features as compared to the standard edition (J2SE). If you are creating your project on J2SE then you must not use any feature of J2SE in project that is not provided by J2ME (mobile edition have limited features).

In jdk1.5 there are some major specification changes due to which it generates different byte-code number that results in "ALERT: java/lang/ClassFormatError: Bad version information". So you need to run/compile your common (J2SE) project on jdk1.3/1.4

Next I have created J2ME as a Common Project:

I am using Netbeans 6.7 for development, so I have created 'Java ME > Mobile Class Library' project for common code. The Mobile Class Library is a mobile project but does not contain any Midlets. It uses IDE-generated Ant build scripts and special tasks to pre-process, build, obfuscate, preverify, debug, run and depoly your library in JAVA ME Environment.

I moved all my common code in this mobile project and then use it as a dependency for both client (J2ME) and server (J2SE) projects and it works properly for both editions. Doing this ensures the compatability of both versions because mobile edition features are already supported by standard edition. Also you will be free from jdk-versioning issue that was faced in previously.

So create 3 different projects, one is a client (J2ME), another is a server (J2SE) and a common project (J2ME) that will be used by client and server.


Monday, April 5, 2010

Share Folder Between Ubuntu (host) and WinXP (guest) on Virtual Box

Following steps helps me to successfully share folders between host and guest:

  • On VBox (Windows) add a shared folder from Devices > Shared Folders. Write the folder name here as well.
  • Now in guest (WinXP), use the "Add Network Place Wizard" in Windows. Follow the wizard and look for you shared folder, add it and you're done.