简体   繁体   English

将Eclipse项目导出到jar

[英]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.. 我一直在网上搜索大约4个小时,并尝试了许多不同的方法来解决我的问题。

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. 我试图用Java制作Pong游戏,现在我想导出我的项目,以便可以将其发送给某个朋友,以便他可以尝试。

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. 我在本项目中使用LWJGL,因此我确实将一些jar添加到了所引用的库中,并且LWJGL.jar在项目lib文件夹中添加了Windows本机。 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: 在阅读有关为何jar无法正常工作的信息时,我还读到您需要一个Manifest.mf文件,因此我创建了一个文件,并且在此清单文件中有以下文本:

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. 在类路径下也有2个空行,因为我听说你必须要这样做。

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: 只要我在eclipse中运行它,该项目就可以正常运行,但是当我使用可运行jar或jar向导在eclipse中导出该项目时,当我双击.jar文件时它不会启动,因此我进入了cmd并使用了以下命令:

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. 我至少检查了10次,我为主要课程提供了正确的路径。而且我不知道该怎么办。 In the eclipse wizard i have been trying both to export runnable jar and exporting normal jar but none of the two is working. 在eclipse向导中,我一直在尝试导出可运行的jar和导出普通的jar,但是两者都不起作用。 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. 另外,在向导中,我选择了导出无法运行的普通jar,因为当我选择可运行时,由于lib文件夹被替换,库变得混乱。

I tried opening the jar file as an archive and got the following: 我尝试将jar文件作为档案打开,并得到以下信息:

In an attempt of using JarSplice i suceeded to solve the problem. 为了尝试使用JarSplice,我成功地解决了这个问题。

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. 由于您需要将本地文件放在jar旁边,并通过'-Djava.library.path'参数指向它们,因此它无法按照您当前尝试的方式工作。

If you just want a single jar and want to avoid the hassle of the command line and native files use the JarSplice tool. 如果您只想要一个jar,并希望避免命令行和本机文件的麻烦,请使用JarSplice工具。 JarSplice is easy to use and will automatically handle the native file stuff for you. JarSplice易于使用,并将自动为您处理本机文件。

1) Simply export your project (class and resources) to a jar (easier just to do it through your IDE). 1)只需将您的项目(类和资源)导出到jar中(只需通过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). 2)然后运行JarSplice,将所需的所有jar添加到jars选项卡(您的应用程序jar,lwjgl.jar以及您使用的任何其他外部jar)。

3)Then on the natives tab add all the natives files (windows *.dll, linux *.so, mac *.dylib & *.jnilib). 3)然后在“本机”选项卡上添加所有本机文件(Windows * .dll,Linux * .so,mac * .dylib和* .jnilib)。

4)On the class tab add your main class. 4)在课程标签上,添加您的主课程。 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'). 然后,只需双击它即可运行该jar(或者,如果希望通过命令行使用'java -jar yourapp.jar')。

I found this solution from this link: Can't start .jar file (using LWJGL) 我从以下链接找到了此解决方案: 无法启动.jar文件(使用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. 我第一次没有使用它的原因是我没有使用JarSplice时从eclipse导出的实际.jar文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM