Skip to main content

External JAR file in a ME application

2 replies [Last post]
genos
Offline
Joined: 2006-05-23
Points: 0

I have been create a MIDlet application that uses a socket connection with a server. The data send throught this connection are serialized and deserialized in both ends of the connection by an object that uses a set of classes to codify the data.
Thus, if the classes used in the MIDlet are the same that one used in the Servlet, there are some way to create an expecific JAR file to be used for both sides?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

In JavaME there can only be 1 jar file for the deployment. Unlike JavaSE where you can add a jarfile to the classpath, ME doesn't provide that feature. However you should be able to build a Jarfile that has your code and place it in the lib directory of your WTK project. When the project is built it should pull the classes out and reconstruct a new Jarfile with your midlet and data objects from the shared jarfile.

HOWEVER, you must compile your classes that will be on both ME and the server with the same target that can be supported on JavaME. (typically this is -target 1.1) Keep that in mind for your build process. Unfortunately I've not seen an IDE that will support a mix of targets in the build, nor will build multiple jarfiles. So you will need to setup different projects for the common files from you server or ME code.

If you use ANT then it's no big deal, just setup another target that compiles and jars for the common separate from your server or ME code.

Hope that helps.
-Shawn

Terrence Barr - Evangelist, Java Mobile & Embedded

Excellent answer Shawn.

Some observations on my side: I've found object serialization difficult
to implement in mobile environments for the reasons Shawn lists. What
I prefer to do is to write my own simplified serialization routines
that send UTF-8 encoded strings (or JSON or something similar) between
both ends and can be smart about how to serialize and deserialize because
they know the context. It is a compromise between effort, compactness
of data, and portability and generally works well.

You might want to take a look at the JSON libraries in the ME Application
Developers project

https://meapplicationdevelopers.dev.java.net/mobileajax.html

-- Terrence

meappdev-interest@mobileandembedded.org wrote:
> In JavaME there can only be 1 jar file for the deployment. Unlike JavaSE where you can add a jarfile to the classpath, ME doesn't provide that feature. However you should be able to build a Jarfile that has your code and place it in the lib directory of your WTK project. When the project is built it should pull the classes out and reconstruct a new Jarfile with your midlet and data objects from the shared jarfile.
>
> HOWEVER, you must compile your classes that will be on both ME and the server with the same target that can be supported on JavaME. (typically this is -target 1.1) Keep that in mind for your build process. Unfortunately I've not seen an IDE that will support a mix of targets in the build, nor will build multiple jarfiles. So you will need to setup different projects for the common files from you server or ME code.
>
> If you use ANT then it's no big deal, just setup another target that compiles and jars for the common separate from your server or ME code.
>
> Hope that helps.
> -Shawn
> [Message sent by forum member 'sfitzjava' (sfitzjava)]
>
> http://forums.java.net/jive/thread.jspa?messageID=250866
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@meapplicationdevelopers.dev.java.net
> For additional commands, e-mail: interest-help@meapplicationdevelopers.dev.java.net
>
>
[terrence.barr.vcf]
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@meapplicationdevelopers.dev.java.net
For additional commands, e-mail: interest-help@meapplicationdevelopers.dev.java.net