Exporting eclipse project to jar - java

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.

Related

JFreeChart Java JAR not running on a different machine

I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.

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.

Export LWJGL natives with project? (IntelliJ IDEA)

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?

JAR File not exececuting which is build by netbeans

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.

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