The program runs as it should in eclipse, however when I try running it as a Jar it throws a noClassDefFoundError.
I assume this is due to an imported jar (commons-io-2.4.jar) that does not get added to the classpath. Apparently I only need to add this jar to the lib folder. Problem is, I can't find this folder (in the workspace there are only .setting, bin and src, as well as a .classpath and a .project file) and I haven't found any options in the Projects properties that would solve this problem.
How do I do this in eclipse?
Add the jar in source dir or project folder then select in eclipse, right-click will give you to add the jar in classpath
Related
I am creating a SWT/JFace project and exporting as executable jar. But this jar is not working on the other computers. When use double clicks the jar nothing happens. I am sure that other user has JRE installed.
I think problem is the Referanced Libraries. Beause near the libraries its written
C:\Users\Turgut - İhracat.p2\pool\plugins\org.eclipse.osgi_3.12.50.v20170928-1321.jar
Here is the Screen capture of libraries. Any helps will be apriciated..
Remove all referenced jars,
Create a 'lib' folder in your project,
Paste your referenced jars into
'lib' folder;
Add these jars into 'classpath'
If this not work, execute your jar via command line to see the error.
I have a maven project loaded in eclipse that when I go to export it as jar, the src/main/resources files always end up in the /resources directory inside the jar. I found a kludge to get around this by putting all my resources in the root directory of the project, but it's getting very messy very fast. Is there any way to configure it so the resources output to root of jar?
you dont export a maven project as jar.
you clean package it and you get the resulting jar at the target folder.
right click the project's pom.xml and run it as maven build.
My java project uses javax.mail.jar. So, in netbeans, I created a new folder Libraries, copied the jar file there and added this in project properties. I added this folder to git and this runs fine on netbeans. But when I build the project with ant on another machine and run the project jar with
java -jar myproject.jar
I get the error
Exception in thread "main" java.lang.NoClassDefFoundError:
javax/mail/MessagingException
I can see that myproject.jar contains the dependent library
$jar tf TakServer.jar
Libraries/
Libraries/javax.mail.jar
...
I'm not sure what is going wrong. Any idea how to get it to run?
Solution: As #Gimby pointed out, the jar files from Netbeans and ant build are different. Netbeans includes a lib/ folder containing all dependencies in dist/ folder and its MANIFEST.ML adds lib/ to classpath. The Libraries folder inside the main jar is not used at all.
The ClassPath in the manifest points to the filesystem outside the jar.
It it not possible to use jars inside jars
https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
I have a jar file I could attach it to project reference library, but it does not have META-INF folder. Does attaching a jar by configuring build path still works?
If you are talking about Eclipse, yes, a .jar file without a META-INF folder works on the build path of a project. I just tried it.
When i clean and build my project using netbeans , though it makes the jar file of the project but it doesn't keep those files that i myself kept in the project folder. That includes some class files,a music file. What is the reason for this ? How do i do this ? I want to keep some class files not generated by the netbeans and also the music file.
What is the reason for this ? default Netbeans build.xml don't include other lib files.
If you look the dist folder you can see a lib folder too. This is your lib folder. If your lib files is in the classpath you jar run on every where if not your file look ./lib/*.jar
You can change your project to ant project or maven project and change your manifest and other files.