将eclipse项目导出到jar [英] Exporting eclipse project to jar

查看:142
本文介绍了将eclipse项目导出到jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实检查了这个问题几乎相同的问题,但没有一个可以解决我的问题。



我已经在线搜索约4小时,尝试了很多不同的事情来解决我的问题。



我试图在Java中制作一个乒乓球游戏,现在我想出口我的项目,所以我可以发送给一些朋友,所以他可以尝试。



我使用LWJGL这个项目,所以我有一些jar添加到引用的库,而LWJGL.jar有添加的Windows本机被包括在项目lib夹。
这是项目查看器的图像:




发布此图片的原因是,您可以了解到,我拥有项目中的所有图书馆以及项目所需的本地图书。



在阅读关于为什么jar不工作的同时我也读到你需要一个Manifest.mf文件,所以我创建了一个和这个清单文件里面我有以下文本:

  Manifest-Version:1.0 
主类:jGame.Main
类路径:lib / jars / asm-debug-all.jar lib / jars / jinput.jar lib / jars / lwjgl.jar lib / jars / izma.jar lib / jars / slick.jar

在Class-Path下面还有两行空行,因为我听说你必须这样做。



这个项目运行良好,因为我在eclipse中运行它,但是我导出项目与可运行的jar或jar向导在eclipse它不会启动,当我双击.jar文件,所以我进入了cmd并使用d这个命令:

  java.exe -jar JGame.jar 

并显示以下消息:





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



我尝试打开jar文件作为存档,并得到以下内容:

解决方案

在尝试使用JarSplice时,我已经成功解决了这个问题。



阅读完后: >



它不会以您目前的方式工作,因为您需要拥有本机文件沿着瓶子,并通过'-Djava.library.path'参数指向


如果你只是想要一个单一的jar,并希望避免麻烦的
命令行和本机文件使用JarSplice工具。 JarSplice是
易于使用,并将自动处理本地文件的东西
你。



1)简单地导出您的项目(类和资源) (/ $)

2)然后运行JarSplice,将所需的所有jar添加到jar选项卡(您的
应用程序jar,lwjgl.jar和您使用的任何其他外部jar)。



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



4)在类标签中添加您的主类。然后创建你的jar。



然后你可以通过双击它运行这个jar(或者如果你希望
通过命令行使用'java -jar yourapp。 jar')。


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



它没有工作的原因我第一次使用JarSplice时没有包含从eclipse导出的实际.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:

解决方案

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.

这篇关于将eclipse项目导出到jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆