🔒 Locked
[java] Eclipse add library problem
Advertisement
Original Post
Hey guys, I'm having a bit of trouble adding a library to my project. I have created a sub folder lib in my project folder, and put the JAR file into that (nanoxml-lite-2.2.3.jar). I then added the JAR to the build path in the Libraries tab of the Build Path editor. Now this all works fine when I'm in Eclipse. I can navigate through the JAR under the Package Explorer, and I can reference the files while editing code. The problem comes when I launch the application. I'm writing a MIDlet, emulating it with the Motorola emulator. I get no errors when the app is building, but when I am running it and it gets as far as that classes call it throws out "ALERT: Unable to load class nanoxml/XMLElement" and shuts down. I'm using Eclipse 3.2.1, Java 6, WTK 2.2, Motorola SDK 6.3 for Motorola OS Products and its bundled EclipseME 1.5.0 plugin. Anyone have any ideas?
The problem is that the classes in the jar that you are compiling against are not being included into the MIDlet jar.
The best way of fixing this is to make sure that the jar file you've speficied in the Libraries tab of the Java Build path is selected in the "Order and Export" tab.
Go to Properties->Java Build Path->Order and Export and click the jar file you want to compile against. Build the project as normal and when you create the package the necessary files should be included into the jar.
The best way of fixing this is to make sure that the jar file you've speficied in the Libraries tab of the Java Build path is selected in the "Order and Export" tab.
Go to Properties->Java Build Path->Order and Export and click the jar file you want to compile against. Build the project as normal and when you create the package the necessary files should be included into the jar.
Quote:
Original post by trojanman
The problem is that the classes in the jar that you are compiling against are not being included into the MIDlet jar.
The best way of fixing this is to make sure that the jar file you've speficied in the Libraries tab of the Java Build path is selected in the "Order and Export" tab.
Go to Properties->Java Build Path->Order and Export and click the jar file you want to compile against. Build the project as normal and when you create the package the necessary files should be included into the jar.
I've checked inside the MIDlet jar, the JAR file has been added. Still getting the error.
Have you made sure that the jar file is clicked in the "Order and Export" tab?
Is it the whole jar file? or the individual class files? What you need is the individual class files to be included into the jar file.
Take this as an example.
[[included_library.jar]]
[folder1]
1.class
2.class
You have called and compiled against 1.class and 2.class and at runtime it needs to load class 1 & 2. You have a MIDlet1.java file and two other classes a & b who are using the 1 & 2 classes from the included library.
What you want in the resultant MIDlet jar file is:
[[MIDlet.jar]]
[folder]
1.class
2.class
MIDlet1.class
a.class
b.class
I hope this explains what I mean.
Is it the whole jar file? or the individual class files? What you need is the individual class files to be included into the jar file.
Take this as an example.
[[included_library.jar]]
[folder1]
1.class
2.class
You have called and compiled against 1.class and 2.class and at runtime it needs to load class 1 & 2. You have a MIDlet1.java file and two other classes a & b who are using the 1 & 2 classes from the included library.
What you want in the resultant MIDlet jar file is:
[[MIDlet.jar]]
[folder]
1.class
2.class
MIDlet1.class
a.class
b.class
I hope this explains what I mean.
Its adding the entire JAR file under a folder called "lib" (basically echoing the way its structured on the disk), whether I add it using "Add Jar", or "Add External Jar". Its checked in the "Order and Export" tab, and I get the same error regardless of whether its positioned above of under the Java ME class libs.
I have started getting an error "Error preverifying class nanoxml.XmlElement" in the problems tab just under the code editor now, though I would imagine thats related to the fact that the entire JAR is being added?
I have started getting an error "Error preverifying class nanoxml.XmlElement" in the problems tab just under the code editor now, though I would imagine thats related to the fact that the entire JAR is being added?
I just set up a test project and under the build path I added an jar via "Add External Jar's" and than I made sure it was selected in the "Order and Export".
When I create my package the class files get included in and I have no problem loading them in and no problems running them.
Have you tried it just using the J2ME WTK as the default build profile?
Also, in the .classpath file I have this entry:
For the preverification, when you build and create the package it should create a folder in the navigator called "verified", in it you should see the verified classes and then a folder called "libs" where the included external library is.
When I create my package the class files get included in and I have no problem loading them in and no problems running them.
Have you tried it just using the J2ME WTK as the default build profile?
Also, in the .classpath file I have this entry:
For the preverification, when you build and create the package it should create a folder in the navigator called "verified", in it you should see the verified classes and then a folder called "libs" where the included external library is.
Quote:
Original post by trojanman
I just set up a test project and under the build path I added an jar via "Add External Jar's" and than I made sure it was selected in the "Order and Export".
When I create my package the class files get included in and I have no problem loading them in and no problems running them.
I just deleted all references to the JAR and re-did the entire thing, right-clicking on the project root, "Add External Archive", made sure it was checked in the Order and Export tab, and still the same thing.
Quote:
Original post by trojanman
Have you tried it just using the J2ME WTK as the default build profile?
The app runs fine when I remove all mention of the external JAR from it. Its runs anyway but crashes out when it can't find the class it needs to load.
Quote:
Original post by trojanman
Also, in the .classpath file I have this entry:
I have a similar entry.
Quote:
Original post by trojanman
For the preverification, when you build and create the package it should create a folder in the navigator called "verified", in it you should see the verified classes and then a folder called "libs" where the included external library is.
The libs folder is present, but there is nothing in it.
This is really starting to do my nut in.
I just created a new project, imported the source files, and Added an External Jar, checked in Order and Export, and instant preverification warning again.
I just created a new project, imported the source files, and Added an External Jar, checked in Order and Export, and instant preverification warning again.
Is it still the whole jar that is getting included into the MIDlet jar?
If so, than there is definately something else wrong.
At this point I'm not too sure. I would just make sure you set up the IDE correctly and have everything from Eclipse and EclipseME installed right. Go through the steps outlined here and see if everything matches. Its been some time since I set up Eclipse to work with J2ME.
If so, than there is definately something else wrong.
At this point I'm not too sure. I would just make sure you set up the IDE correctly and have everything from Eclipse and EclipseME installed right. Go through the steps outlined here and see if everything matches. Its been some time since I set up Eclipse to work with J2ME.
[sad]
I think I cracked it. I decided that I would just download and import the source. I was still getting errors so I dove in to find a shed-load of "cannot be resolved to a type" errors. Half the classes used aren't available under either the MIDP or the CDLC, it was obviously developed using Java SE. Sun's JWT FAQ suggests that this would be a cause for preverification failure. I wouldn't mind but this is the second parser I tried...
So now I have to go looking for another "ME-compatible" XML parser. EIther that or lose time hacking the one I have until it works.
Thanks anyway, trojanman. Rate++ for your time and patience.
I think I cracked it. I decided that I would just download and import the source. I was still getting errors so I dove in to find a shed-load of "cannot be resolved to a type" errors. Half the classes used aren't available under either the MIDP or the CDLC, it was obviously developed using Java SE. Sun's JWT FAQ suggests that this would be a cause for preverification failure. I wouldn't mind but this is the second parser I tried...
So now I have to go looking for another "ME-compatible" XML parser. EIther that or lose time hacking the one I have until it works.
Thanks anyway, trojanman. Rate++ for your time and patience.
No worries aidan_walsh, a few other people around here have had some troubles with getting external libraries in via Eclipse, it was a nice refresher for me.
As for the ME compatible XML parser, I am not familiar with one, and unfortunately there might not be a good one. One place to check though would be at <a hred="http://www.j2meforums.com>www.j2meforums.com. This is a pretty good forum with a large base of indie and pro developers who might have some extra resources.
As for the ME compatible XML parser, I am not familiar with one, and unfortunately there might not be a good one. One place to check though would be at <a hred="http://www.j2meforums.com>www.j2meforums.com. This is a pretty good forum with a large base of indie and pro developers who might have some extra resources.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement