Export JAR file not working - java

I've been working on a project in eclipse for a while and now I need to export it as a JAR file so that I can transfer it to other computers and share it with the people I am working with.
Having never exported anything as a jar before, I googled how to export a jar file and followed the instructions and finally exported. However, whenever I do this (I have tried exporting my project multiple times before asking a question here), I always get the message that my classes have been exported with compile warnings.
Additionally, when I try to launch the jar file, I get a message that it cannot be launched. I have tried everything I can think of to get the jar to export and I have looked at a lot of different questions looking for a solution to my problem, but I can't seem to find one. I'm at my wits end, and if anyone could give me a way to fix this problem, I would be very grateful.
Thanks for the help!

Copy your jar somewhere else on your computer and check if it is working fine.
It might be because of depending classes. To overcome this, add your additional jars when you compile your jar using eclipse to have a little big jar: File -> Export -> Java -> Runnable JAR File -> (then choose) Package required library.... option.
Also, when you deliver your jar, you may ask your client to run CMD (for windows) and then check "Java -jar {your jar file name}" to see what is going on there on their computer.

Related

Eclipse not exporting external jar libraries

I'm trying to make this .exe file of my eclipse project for my teacher, but every time I do it gives me errors claiming that the lwjgl libraries aren't in there. However when I exported the runnable jar from eclipse that I used to make the .exe from, I selected "Package required libraries into generated jar." I tried running the .jar through the command prompt, but it gave me these errors (click the link): https://scontent-dfw.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/11059766_1609765759310316_8110952137507721084_n.jpg?oh=af235bc0bdb7ecf1e4d875619bd20631&oe=55D1E928
I don't know why it's doing this. I need this executable by tomorrow and it's already like 10:47 PM and I'm freaking out! Could someone PLEASE help me?!?!
EDIT
I tried selecting "Extract required libraries into generated JAR" instead, but gave me "java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path"
I solved my problem! I changed the lwjgl libraries from being an external library to it being in a folder inside the project, and then I exported it with the required libraries outputed to a folder next to the jar, and then created a fat jar using JarSplicer. Now, however, I'm having this other issue that makes it unable to get image and sound resources even though (I checked with 7-zip) they are in the correct file position. I'll post another question for this other problem.

Building Java Project can't access external jar referenced libraries?

My program runs exactly as it should when I run it out of eclipse, but when I try to build it into a runnable jar I get problems.
When I set Library Handling to Extract required libraries into generated JAR, or Copy required libraries into a sub-folder next to the generated JAR, the program runs but doesn't do anything that involves the external libraries. When I set it to Package required libraries into generated JAR, absolutely nothing happens when I try to run the JAR.
At this point I have no idea what to do after spending the past hour looking online for solutions, library handling seems to work fine for everyone else?
I'm using eclipse 4.4.1 if it makes a difference
First check to make sure you have the libraries. To do so open up the jar file with win rar or something similar. If the libraries are missing you can just copy and paste them into the jar file.
If they are there then you can create a batch file (If using windows) to run your jar file with the java command. Doing this will give you a console in command prompt to view output and stack-traces. This can help you find where the problem is.
Command for .bat file:
java -jar jarfile.jar
If you don't want to create a batch file and run it from command prompt, remember to make the cmd path the same as the jar file location.

Exported runnable .jar File w/ Eclipse using libgdx

So my problem is that I want to export my libgdx desktop project as a runnable .jar file. I already made this work and it is working fine when I open the .jar file from my desktop. However, if I put the .jar file into my Dropbox or in any other directory other than my Desktop, it won't work anymore. The Gameframe opens for like 0.2sec, stays black and closes again immediatly. If I then pull the .jar back to my Desktop it works fine.
I've seen other people ask this before, but none of the answers helped me with my problem.
If you need any more info please let me know!
Try opening the exported JAR in (for example) 7-zip and then adding the 'res' folder manualy. I don't really understand, why Eclipse didn't put the 'res' folder in it. But adding it manualy worked for me.
In eclipse, make sure to right-click the whole project and click export. In library handling, click on "Package required libraries into generated JAR". Then click finish. If that does not work, make sure your build path includes everything.
Can I have access to the .jar file so I can look what is missing inside it?
Most likely you got some additional libraries in your output directory which are missing when you place your jar in dropbox. To confirm this try to start your application via command line. Java will then print a stacktrace with the exception. Example:
java -jar yourjarinthisdirectory.jar
As a side note I would recommend to use maven in the future maven libgdx. In this case you just can say "package" and maven produces complete jar with all libs inside it without further configuration.

Exporting eclipse project to jar

I did check the already answeared questions which have almost the same topic as this question but none of the answeared onces were able to solve my problem.
I have been searching now online for about 4 hours and tried soo many different things to solve my problem..
Im trying to make a Pong game in Java and now i wanted to export my project so i can send it to some friend so he can try it.
Im using LWJGL for this project so i do have some jars added to the referenced libraries, And the LWJGL.jar has the windows natives added which is included in the projects lib folder.
Here is an image of the project viewer:
Reason im posting this image is so you get an idea of that i have all the libraries inside the project aswell as the natives needed for the project to run.
While reading about why the jar didnt work i also read that you need a Manifest.mf file so i created one and inside this manifest file i have the following text:
Manifest-Version: 1.0
Main-Class: jGame.Main
Class-Path: lib/jars/asm-debug-all.jar lib/jars/jinput.jar lib/jars/lwjgl.jar lib/jars/izma.jar lib/jars/slick.jar
Also 2 empty lines underneath Class-Path since i heard u have to have that.
This project runs fine aslong as i run it in eclipse but when i export the project with either runnable jar or jar wizard in eclipse it doesn't start when i double click the .jar file so i went into the cmd and used this command:
java.exe -jar JGame.jar
And the following message was shown:
I have checked atleast 10 times that i provided the correct path for the main class.. And i dont know what to do anymore. In the eclipse wizard i have been trying both to export runnable jar and exporting normal jar but none of the two is working. Also in the wizards i have selected to export a normal jar not runnable since when i choose runnable the libraries get messed up because the lib folder gets replaced.
I tried opening the jar file as an archive and got the following:
In an attempt of using JarSplice i suceeded to solve the problem.
After reading this:
It's not going to work the way you're trying to currently do it, since you need to have the native files along side the jar and point
to them via the '-Djava.library.path' parameter.
If you just want a single jar and want to avoid the hassle of the
command line and native files use the JarSplice tool. JarSplice is
easy to use and will automatically handle the native file stuff for
you.
1) Simply export your project (class and resources) to a jar (easier
just to do it through your IDE).
2) Then run JarSplice, add all the jars you need to the jars tab (your
app jar, lwjgl.jar, and any other external jar you're using).
3)Then on the natives tab add all the natives files (windows *.dll,
linux *.so, mac *.dylib & *.jnilib).
4)On the class tab add your main class. Then create your jar.
You can then run this jar just by double clicking it (or if you wish
via command line using 'java -jar yourapp.jar').
I found this solution from this link: Can't start .jar file (using LWJGL)
Reason why it didnt work the first time were i didn't include the actual .jar file that was exported from eclipse while using JarSplice.

Eclipse Runnable Jar Export Not Launching

I am currently working on a game in Java and tried to export my first release as a runnable jar.
As Eclipse has a tool for this, I tried to use it.
After trying many different ways, I could still not launch the game. I made sure to export as a runnable jar and added the library.
My suspicions are as follows: The game's project is set up like this: src->package->code, Res->images and so on, JRE System Library, and finally referenced libraries->Slick2d, lwjgl, and jinput.
As it happens, I could find no way to get the jar to replicate the workspace folder organization. I believe that is what is causing it to crash; the required files are in unknown paths to the program.
I then tried to reorganize the files myself, only to be told that the jar is corrupted.
If anyone could please help by telling me what the issue may be, how to fix it, or any tips what-so-ever, I would be very thankful!
Use JarSplice to include the library, your jar and the natives in 1 jar.
It didn't work because natives and slick jars were missing.
eclipse comes with the option to package the required Jar along with the main Jar.

Categories