简体   繁体   English

使用libgdx导出带Eclipse的可运行.jar文件

[英]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. 所以我的问题是我想将我的libgdx桌面项目导出为可运行的.jar文件。 I already made this work and it is working fine when I open the .jar file from my desktop. 我已经做了这项工作,当我从桌面打开.jar文件时,它工作正常。 However, if I put the .jar file into my Dropbox or in any other directory other than my Desktop, it won't work anymore. 但是,如果我将.jar文件放入我的Dropbox或除我的桌面以外的任何其他目录中,它将不再起作用。 The Gameframe opens for like 0.2sec, stays black and closes again immediatly. 游戏框打开大约0.2秒,然后保持黑色,然后立即关闭。 If I then pull the .jar back to my Desktop it works fine. 如果然后将.jar拉回到我的桌面,则可以正常工作。

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. 尝试在7-zip中打开导出的JAR,然后手动添加“ res”文件夹。 I don't really understand, why Eclipse didn't put the 'res' folder in it. 我真的不明白,为什么Eclipse没有在其中放入“ res”文件夹。 But adding it manualy worked for me. 但是手动添加它对我有用。

In eclipse, make sure to right-click the whole project and click export. 在eclipse中,请确保右键单击整个项目,然后单击“导出”。 In library handling, click on "Package required libraries into generated JAR". 在库处理中,单击“将所需的库打包到生成的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? 我可以访问.jar文件,以便查看其中缺少的内容吗?

Most likely you got some additional libraries in your output directory which are missing when you place your jar in dropbox. 很可能在输出目录中还有一些其他库,当您将jar放入保管箱时,这些库会丢失。 To confirm this try to start your application via command line. 要确认这一点,请尝试通过命令行启动您的应用程序。 Java will then print a stacktrace with the exception. 然后,Java将输出带有异常的stacktrace。 Example: 例:

java -jar yourjarinthisdirectory.jar java -jar yourjarinthisdirectory.jar

As a side note I would recommend to use maven in the future maven libgdx . 附带说明一下,我建议在将来的maven libgdx中使用maven。 In this case you just can say "package" and maven produces complete jar with all libs inside it without further configuration. 在这种情况下,您只需要说“ package”,maven便会生成包含所有库的完整jar,而无需进一步配置。

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

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