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.
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.
I'm using eclipse and ant to compile a java project. The ant compile script calls javac using a classpath refid of classpath, which is set based on System Property variable java.build.path.
My java.build.path variable is missing a library that was specified in
Project->Properties->Java Build Path->Libraries.
That is, the external jar was properly added to the list of libraries to add to the build path, is not missing or corrupt, and I have every expectation that eclipse would include the library in the build path. My build fails because java.build.path is missing this library.
Furthermore, the file <projectDir>/.classpath contains a valid classpathentry element for the missing jar file.
When building, javac fails at an import statement, claiming that the package does not exist. The value of java.build.classpath contains many of the libraries I set in the project properties, but does not include the missing library. Its as if the project property for that external jar was never set.
For what its worth, the missing library is jboss/lib/jbosssx.jar
Any help here would be appreciated.
At first,
Download jbosssx.jar jar file from this link
Then keep the jar file in the folder jboss/lib
Hope it will solve your issue.
UPDATE:
Sometimes jar files need to keep in lib folder physically. For this reason, you can put the jar file in your project lib folder.
I found where my configuration was messed up.
Using External Tools Configurations within eclipse, I found another Classpath settings tab for my ant build that did not contain my library.
Adding my library here caused the build to succeed!
Skywalker, thanks for the suggestion. :)
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
I have a Java project in Eclipse with class MainClass having main method in package :
com.nik.mypackage.
The project also references two external libraries, which I copied in the lib folder in Eclipse and then added to build path using ADD JAR function. The libraries being one.jar and two.jar
This library is in lib folder in eclipse and added to the build path.
I want to create a executable JAR of the application using ant script. So that user can access my application using command:
c:>java -jar MyProject-20111126.jar
I know about the Eclipse plugin which directly exports a java application as runnable JAR. But I want to learn ant and the build process so manually want to create the build.xm.
You have two options from your build.xml. You can either unjar the library jars and then bundle their contents with the code compiled for your application. Or, you can put the library jars on the filesystem and supply a ClassPath entry in the manifest file of the MyProject-2011126.jar file.
If you set the classpath in the manifest remember that the path you supply is relative to the MyProject-2011126.jar.
one alternative:
Instead of having only a jar, you build mutiple jars (your jar + libs) +batch file.
So, your built package can be like this structure:
-/package/bin/app.bat
/package/lib/my.jar
/package/lib/one.jar
/package/lib/two.jar
In app.bat you just have the same as your code
java -jar MyProject-20111126.jar
PS: if you want to start learning built tools, ANT may be a bit tool old. I suggest http://maven.apache.org/
Please try one-jar. It helps to redistribute everything packaged as single jar and comes with ant-task . See Easiest way to merge a release into one JAR file.
I created a JAR file from my java project.
Using Eclipse, I added a JAR as a referenced library in my own project.
However, now when I try to run my program's JAR using java -jar myProgram.jar, I get an exception stating that my referenced jar is not available.
So how can I create a JAR consisting a reference to a different JAR and make it work?
Right, an executable JAR cannot contain its own JAR dependencies.
You have to have the main class and classpath set in the executable JAR manifest, then package all your JAR dependencies along with the executable JAR in a relative directory structure that matches the manifest CLASSPATH. Reading this might help.
You need to use Eclipse's runnable JAR exporter. Since Eclipse 3.5 you've the following options when you rightclick project, choose Export > Runnable JAR file:
Either way, Eclipse should take care that you'll be able to run the JAR the way you want on the exported location.
See jarjar project. It is exactly what you are looking for. http://code.google.com/p/jarjar/