I'm currently working with J2me by Mobile Tools for Java (MTJ) on Eclipse. My program need to encrypt SMS messages by RSA so i try to use bouncycastle library. I download bouncycatle version 1.47 and add to to my buildpath. No problem occurs when building project. But when i try to run on emulator, i get this error:
TRACE: <at java.lang.NoClassDefFoundError: org/bouncycastle/crypto/engines/RSAEngine>, startApp threw an Exception
It's a common problem, NoClassDefFound. To solve this, i know i must include the class file of bouncycastle in classpath. But here come the problem, i cant pack bouncycastle class file into the jar which MTJ created. For regular project, all i need to do is tick on the checkbox in "Order and Export" tab to have all class files in the "ticked" referenced library packed in to output jar. I do the same here but after i create package, i check the new jar file and no class of bouncycastle is inside (check using WinRar).I did some
I'm using Eclipse Indigo Release 2, build-id: 20120216-1857, MTJ version 1.1.2.
I also tried to create package by eclipse Pulsar 1.3.1 but the problem still persists.
Is there any suggestion? is this a bug?
Regards.
"Order and Export" is not working as you think it is. If you have two projects - ProjectA and ProjectB and ProjectA dependends on ProjectA, then if ProjectA needs some.jar and you find out that ProjectB needs some.jar too, then "Order and Export" for that jar in ProjectA makes it "visible" also for ProjectB.
For JAR files you cannot add another jar into the JAR files (it works for WARs and EARs). There are two possibilities how to solve this
you can unzip required JAR and add class files to your jar, jar -u can help you (this seems difficult, but if you are using ant or maven you will configure that once)
you can try to use MANIFEST headers
Related
I'm trying to find more information on how eclipse handles Running a project.
I want to understand it more because I have an issue I'm currently having where apache-poi .jar files which have been included into the classpath of my project will work properly when the project is ran through eclipse, but will not be detected when going to the same projects folder and running the main jar file to start the program.
It gives me the error: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell (although sometimes instead of Cell, it's Sheet)
What could I consult to understand what is going on here, and possibly solve this issue?
Your NoClassDefFoundError indicates that the library was not available while running the jar.
This depends upon how you are exporting your project into the jar file.
If you're using eclipse to do so, you can:
Export->Java->Runnable Jar to create a jar that includes its dependencies
Make sure to check Package required libraries into generated JAR.
This will make all your jars (in build path including apache-poi.jar) as a part of the final jar.
It runs from eclipse because libraries are on the build path of the eclipse which makes them available in the classpath.
My process for creating a runnable JAR from a project with many libraries with Eclipse has been.
Export > Runnable JAR > Select launch configuration > Package required libraries into generated JAR > Finish
This creates a single JAR in my export destination which I FTP to my server and run fine.
I recently switched to IntelliJ for various reasons and it has been an improvement in all cases except for building my JARs which forces me to go back to eclipse temporarily.
With IntelliJ I:
Open Project Structure > Artifacts and create a new JAR from modules with dependencies. I then have my output layout with the name of the JAR, a META-INF inside it and all my libaries with the format Extracted <lib.jar/> (sorry I can't upload screenshots on this VPN.)
I build my artifact (which is about 15MB bigger) and FTP it to my server, try to run it and I get the error:
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
How do I mimic how I do it in Eclipse?
EDIT
The two JARs that are created differ considerably:
The valid jar that Eclipse creates looks like this:
Whereas the invalid .JAR looks like this:
You're facing two issues one seems major and one is minor:
Major: signature exception
Minor: size of the jar is 15 MB greater than the jar produced by eclipse.
The solution of both of the issues lies in the way you are building the artifact. First of all, remove all extracted *.jar then add all the jar's from the available elements pan as shown in the figure.
It is obvious that adding packaged(compressed) jars only, will decrease the size. But it also solves the signing issue. For more explanation, please have a look at this article. I'll only quote one line.
It's probably best to keep the official jar as is and just add it as a
dependency in the manifest file......
It seems that some of the dependencies are signed and repackaging messes up the META-INF of your project.
If you are using Maven you need to put META-INF directory under /main/resources folder instead of main/java.
Reference: Intellij - Nikolay Chashnikov
Then you can execute the runnable jar normally with java -jar filename.jar
You can these steps:
1) File -> Project Structure -> Project Settings -> Artifacts -> Jar -> From modules with dependencies
2) Check the Include in project build checkbox.
3) Right mouse click on module -> build module 'ModuleName'
you could try using a gradle script. eclipse will make you a gradle project. you can use that build file with any ide. it has a built in jar task.
Suddenly, all my code depending on external jars doesn't work.
For example:
Jsoup.parse(str)
gives:
could not resolve type: org.jsoup.Jsoup
And i'm 100% sure that it is in the build path.
Maybe it happenned because I updated the ADT plugin and the platform tools to the latest version, but it doesn't make sense...
But it started occuring since I updated those.
So apparently eclipse doesn't compile those jars. (In code, it DOES resolve the jars types)...
Do you maybe know what is the problem?
This has nothing to do with compilation: jar's are already compiled.
You only need to add the jar to your project classpath so Eclipse will know to run java with the .jar. You can do this with "Context/Right click menu->Properties > Java Build Path > Libraries" (source). For portability I recommend placing the .jar in a subdirectory of your project. A "lib" folder in your project root (where "bin" and "src" are too) is commonly used.
Also note that to run your program you will need to add the dependency .jar to your java command, but with a little searching you can find out how to include the dependency .jar in your own combined .jar.
You have to put the libraries in /libs folder of your project (if you are using Eclipse you choose "Add JARs.." not "Add external JARs..")
I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-path entry for 'C:Projects/this_project/src/com/company/python/'
When browsing through the generated JAR file with an archive manager, the python module is in fact inside of the JAR, but when I check the manifest, only "." is in the classpath. I can overlook this issue by manually dropping the module into the JAR file after creation, but since the main point of this project is automation, I'd rather be able to configure Eclipse to generate properly configured JAR automatically. Any ideas?
*NOTE*I obviously cannot run the program successfully when I do this, but removing the Python source folder from the classpath in "Run Configurations..." makes the error go away.
Figured it out, had to add the source folder with the Python module in it as a class folder in the Build Path project properties. Not sure if this next part is necessary or not, but since the module is not compiled, I added the folder again as "Attached Source" after adding the class folder.
Have a look at the maven-jython-compile-plugin and its demo project at http://mavenjython.sourceforge.net/ . It allows bundling jython with dependencies into a standalone jar.
I'm using 3rd libraries (substance, trident) and I added them as libraries (I added the .jar's) to my project in Netbeans. This works also but if I use the builded jar outside the project directory it doesn't work like it should (the choosen UI don't show), I get the error:
java.lang.ClassNotFoundException:
org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel
I set that UI/LookAndFeel like that in my code:
UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel");
How could I make this work/run?
You've got 2 choices:
Put the library jar on the
classpath.
Assemble\Build the library jar with
the regular jar.
For option 1, you most likely need the jar located "near" the main jar on the file system; though, this is not necessarily a requirement. When you run the jar you then include the library jar on the classpath.
For option 2, you use some type of tool like maven's assembly plugin or the fatjar plugin in Eclipse (sorry, I don't know what the analog is in NB).
I hope this helps.