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.
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 am a Beginner in Java GUI and am using Netbeans 7.3 to use Swing Components, the problem is that all was working fine, but one day when I Clicked Clean & Build and tested the JAR file, it was not executing, I ran it in the Netbeans and It is working fine.
Then I thought that it would be a problem of Build Properties so I compared build properties from a project which was working fine with Jar file but I cannot find any difference, The problem is that when I double-click the JAR file, no Error is shown, I tried many ways like executing it from cmd but It did'nt worked.
Can anyone help me out What could be missing, and one thing more that is I even tried to build my project on another computer through Netbeans but no use.
Try to open your .jar with winrar, and check if the classes are being added to the .jar, If they are not being added probably is a bug from netbeans, I would advise to install netbeans 7.2, and then open your project again, and then regenerate the Jar File. I was having a similar problem with Netbeans 7.3
I think you executing .jar file from different folder - not from where it was created? If so - that means your application can not find some files - pictures, etc. So if you have some files which application uses - create the folder named "lib" and place there your files - but not .jar file. For example:
File file = new File("/images/etc.png");
means that it is placed in lib/images directory. So your .jar file could be run from here:
C:/myTestApplications/myApp.jar
which contains also folder
C:/myTestApplications/lib/images
Try that.
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.
Right now i've written a simple SWT application using eclipse, and I want to pack it into an executable .jar file so I can give it out to friends and such. But I have the following problems:
-Right now i'm reading files by using their filename in the program, and putting them in the root folder of the eclipse project. That works fine for running in eclipse, but when I export to jar they're not in the jar. Is there a way to put them in the jar and access them in the code?
-I also need the SWT .jar dependencies or whatever its called(the files you need for SWT).
Does anyone know how to do this?
Take a look at ClassLoader.getResourceAsStream() API.
All you need to do is include these files in the with the source code of your project, then to have access to then have a look at this link
I just heard of library for reading/writing excel files without COM, so I figured I'd go check it out.
I downloaded jexcelapi_2_6_12.zip from this page http://sourceforge.net/projects/jexcelapi/files/ but I have no idea how to open it in Eclipse.
I know it's a silly question, but I'm sure it's not the first time someone's asked it, how do I open this in Eclipse in Windows, compile, run and debug it?
Primarily what you need from that zip is the jar which contains the library. You'll still need to actually write a Java app that uses it.
So what you need to do is:
Unzip the file you downloaded
create a new java project
add a lib directory to the project
copy jxl.jar from the zip into your projects lib directory
right click on the jar in eclipse and select "Build Path>Add to build path"
The classes in the library are now available to your project
Next create a new java file in your projects source folder and start coding.
Extract the zip file somewhere, put the jar file in your project's directory somewhere (e.g. under a lib directory) and then right-click on it and select "Add to build path" or something similar.
It's not runnable on its own though - you'll need to write some code in order to debug.
If you want to debug into the source code of the library itself, you'll need to tell Eclipse where the source is - but that's unlikely to be necessary.