Using external jars as library | Telit Cinterion IoT Developer Community
June 14, 2016 - 2:11pm, 3772 views
Can we use external libraries in jar format in our projects?
I'm adding some library as jar to project using build path settings in eclipse.
When I use a class of that library in code, it compiles successfully but when it run, java.lang.NoClassDefFoundError occurs.
Why it occurs and how can I solve?
When you open Java Build Path menu you need to check that library for export in Order and Export tab. Then it should be working.
Thanks for the answer.
When library checked eclipse gives preverification error.
Do you know how this preverification mechanism works?
Which jars can be included, which ones can't?
Preverification performs some checks on the Java bytecodes ahead of runtime. If the verification is OK, the preverifier annotates the class files. The virtual machine then doesn't need to do it before running the application. To read about the details of that check you would need to search the CLDC documentation.
But if if failed the first question would be - what jar was used?
On the module there is an embedded Java microedition, profile IMP-NG, configuration CLDC 1.1. This version is limited compared to Java SE and even to regular ME because it is based on Java 1.3 and is prepared for the mobile device with limited resources that does not have a display, keyboard etc.
So it would be good to make sure that the library is compatible with the Java on the module. If it's not and you have no alternative but do have a source code you could try to adopt it. There is probably not much libraries available that you could just use out of the box. So if you have the source code you could unzip the jar and attach the source code to the project. Then you'd be able to make necessary corrections in that code.
Do you have the Java User's Guide document? Have you installed everything and configured the project properly?
Thanks for the detailed answer. I will try importing source codes of a library as you explained.
I have Java User Guide document and I installed wtk and other components properly.
But I didn't see any document about using external libraries with module. About restrictions and rules..
If there is a document, I want to look at. CLDC and IMP specification documents are good sources but too big to analyze. Maybe gemalto can prepare some less detailed documents for developers if does not exist.
The main and only document for Java is Java User's Guide which is quite big. There is no dedicated document for using libraries probably because it's more programming and Eclipse oriented than module but maybe some information could be added according to your hint.
As for the rules the lib ***** to be compatible with the Java on the module so it ***** to use the API's that are provided with the module and nothing more. And it ***** to be compiled for Java version no higher than 1.3. So if you attach the sources to the ME project with only Cinterion Java libraries configured for the project (Java Build Path/Libraries) and no SE Java and it will compile without errors then you are on the good way.
You wrote, "it ***** to be compiled for Java version no higher than 1.3".
I have jdk1.8.0_91 installed on my pc. When creating a Midlet project on Eclipse, jre is not specified.
CLDC and IMP configuration selection is being done at start up. (If you start a Standard Edition project in Eclipse you select jdk version first.)
Thus, probably project is compiled with jdk 1.8. Right? Does it cause a problem?
And in wtk istallation cd, in contribution folder jdk-7u25 exists to use. It is also later than jdk 1.3.
How to select 1.3 for a Midlet project?
In Eclipse you need to open the project properties, go to Java Build Path and make sure that there are the proper libraries from the provided WTK folder. Then you need to go to Java Compiler and make sure that there is 1.3 in JDK Compliance. You should also install the Java from installation CD. The Java User's Guide document should also contain the description how to create the new project.