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.
Related
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.
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.
I'm currently writing a program dependent on LWJGL. Adding the library to my project was easy enough, but I'm having trouble exporting my project as a standalone JAR that the user can simply double-click for a finished product.
WHAT I HAVE TRIED:
File -> Project Structure... -> Modules -> Dependencies tab -> Add -> Jars or directories -> (insert path to natives here) -> Option "classes" in the dialog. -> Check the box under "Export"
DESIRED RESULT: A runnable JAR with no dependency on the command line to open properly. Other JARs and directories being included with my project are fine, but I'd like IntelliJ to export them WITH my project automatically if possible, so that I don't have to manually drag the needed files into the output directory and make a script to run the JAR with the correct natives.
I'm very new to IntelliJ, coming from Eclipse (although I never had to do this in Eclipse, either), and am still coming to grips with the new (to me) terminology used by the program. I'm sure there is a very easy solution I am just overlooking. Thank you in advance.
I was able to get around the issue by using JarSplice to make a Windows EXE that includes the natives within.
I also use IntelliJ, and I've had a similar issue. If you put your natives into a folder somewhere near you, use something like the following at the start of your public static void main method:
System.setProperty("org.lwjgl.librarypath", PATH_TO_LIBS);
Note that you may have to prepend System.getProperty("user.dir") to the front of PATH_TO_LIBS, I'm not certain.
ADDENDUM: You said you'd like any additional files to automatically be created with your jar? Check out IntelliJ's Artifacts. Go to project settings, select artifacts, and add one with the plus button. Once you get an artifact added you can mess around with the file structure on the side, adding in other folders (such as the natives folder, or a resources folders). Once you're done there, you can click Build>Artifacts and it automatically packages them for you, and puts them in a directory (which you can specify on the Artifact window).
I don't know what IntelliJ is so I'm not sure how helpful this will be, but I did do something like this with LWJGL a couple of years ago.
LWJGL depends on native libraries, and the operating system depends on loading those from real native files. You can't load them from inside a jar. So, you can put them in the jar, but you'll have to write some code (which runs before you try to call any LWJGL stuff) which will extract the needed native(s) from the jar at run time and save them in the system temporary directory (or wherever) then load them with System.load.
Then you have to remove/comment out the normal library loading code from org.lwjgl.Sys (the functions doLoadLibrary and loadLibrary). That should do it.
Edit: A similar question is here: How to make a JAR file that includes DLL files?
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.
I need help getting my java program ready for release. I have a program with three packages in each package are classes. Within one package is the class with main that requires all of the other classes when running. My question is how do I build this Java project so anyone can run it. The structure of the files is as follows:
src/table/java files
src/school/java files
src/schoolSort/java files
The main is located in schoolSort/Main.java I have a Windows 7 set up and I have tried:
javac table/*.* school/*.* schoolSort/*.*
And this produced class files but the main file wont run. Help please. I am using Eclipse and have tried that too but it didnt seem to work.
In Eclipse, you can right click on your project and choose to export it as an executable jar. It will ask for your main class (through the run configuration you used) and you should be good to go from there.
Right click on project > Export > Java > Runnable Jar File
You would have to create what is called an executable jar. This is the artifact that you will share with others.
Here is the set of basic steps that you have to follow to create a jar
Here is the set of steps to create an executable jar.
I'm sure eclipse will help you out with these steps, but I have not used it much.
In eclipse, you can do File->Export->Java->Runnable JAR file...
Check your packages are in classpath. If your packages are in classpath, you should try to use 'ant' to build your application.