Exporting eclipse project to jar

坚强是说给别人听的谎言 提交于 2020-01-06 03:27:07

问题


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:


回答1:


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.



来源:https://stackoverflow.com/questions/16132671/exporting-eclipse-project-to-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!