将eclipse项目导出到jar(Exporting eclipse project to jar)

系统教程 行业动态 更新时间:2024-06-14 17:01:34
将eclipse项目导出到jar(Exporting eclipse project to jar)

我确实检查了已经回答的问题,这个问题与这个问题的主题几乎相同,但是没有一个问题能够解决我的问题。

我一直在网上搜索大约4个小时,并尝试了很多不同的东西来解决我的问题..

我试图用Java制作Pong游戏,现在我想导出我的项目,这样我就可以把它发送给朋友,这样他就可以试试了。

我在这个项目中使用LWJGL,所以我确实在引用的库中添加了一些jar,并且LWJGL.jar添加了windows natives,它包含在项目lib文件夹中。 这是项目查看器的图像:

我发布此图片的原因是,您可以了解我拥有项目中的所有库以及项目运行所需的本机。

在阅读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

因为我听说你必须拥有它,所以在Class-Path下面还有2个空行。

这个项目运行正常,因为我在eclipse中运行它,但是当我在eclipse中使用runnable jar或jar向导导出项目时,当我双击.jar文件时,它没有启动,所以我进入了cmd并使用了这个命令:

java.exe -jar JGame.jar

并显示以下消息:

我已经检查了至少10次,我为主要班级提供了正确的路径..我不知道该怎么做了。 在eclipse向导中,我一直在尝试导出runnable jar并导出普通jar,但两者都没有工作。 另外在向导中我选择导出一个普通的jar不可运行,因为当我选择runnable时,库会搞乱,因为lib文件夹被替换了。

我尝试将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..

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:

最满意答案

为了尝试使用JarSplice我成功解决了这个问题。

看完之后:

它不会按照您当前尝试的方式工作,因为您需要将jar文件放在jar旁边并通过'-Djava.library.path'参数指向它们。

如果您只想要一个jar并且想要避免命令行和本机文件的麻烦,请使用JarSplice工具。 JarSplice易于使用,并会自动为您处理本机文件。

1)只需将项目(类和资源)导出到jar(更容易通过IDE执行)。

2)然后运行JarSplice,将所需的所有罐子添加到jar选项卡(你的app jar,lwjgl.jar和你正在使用的任何其他外部jar)。

3)然后在natives选项卡上添加所有本机文件(windows * .dll,linux * .so,mac * .dylib&* .jnilib)。

4)在类选项卡上添加主类。 然后创建你的jar。

然后,您可以通过双击它来运行此jar(或者如果您希望通过命令行使用'java -jar yourapp.jar')。

我从这个链接找到了这个解决方案: 无法启动.jar文件(使用LWJGL)

它第一次没有工作的原因是我没有包含使用JarSplice时从eclipse导出的实际.jar文件。

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.

更多推荐

本文发布于:2023-04-20 18:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/730d2b9e0c8f0a06e74f1dd55296a36d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:导出到   项目   eclipse   project   Exporting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!