eclipse 如何从我的 LIBGDX 游戏中制作可执行文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9029028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make an executable out of my LIBGDX game
提问by Brian Diehr
I've never made a program into an executable before, and I've been looking into how to do this for some time now. When I try to put it into a jar everything works fine but when I try to run it nothing happens.
我以前从未将程序制作成可执行文件,并且我一直在研究如何执行此操作已有一段时间了。当我尝试将它放入 jar 时,一切正常,但是当我尝试运行它时,什么也没有发生。
How do I make my game into an executable so it can be run (on windows, not android) I feel like I am not Linking it to the libraries or something... Not sure. Thanks!
如何将我的游戏变成可执行文件以便它可以运行(在 Windows 上,而不是 android 上)我觉得我没有将它链接到库或其他东西......不确定。谢谢!
Edit: I should add I get the error
编辑:我应该添加我收到错误
JAR export finished with warnings. See details for additional information.
duplicate entry: com/badlogic/gdx/utils/arial-15.fnt
duplicate entry: com/badlogic/gdx/utils/arial-15.fnt
duplicate entry: com/badlogic/gdx/utils/arial-15.png
duplicate entry: com/badlogic/gdx/utils/arial-15.png
Jar export finished with problems.
See details for additional information.
采纳答案by Nacef
Your problem is that when you use eclipse export as Executable jar file it does not include the assets (graphical, sounds ...) that you used in your gdx project. What you can do manually is either copy your assets folder right next to the generated jar file or include your assets folder in your jar file with your favorite zip management tool.
您的问题是,当您将 eclipse 导出用作可执行 jar 文件时,它不包含您在 gdx 项目中使用的资产(图形、声音...)。您可以手动执行的是将您的资产文件夹复制到生成的 jar 文件旁边,或者使用您最喜欢的 zip 管理工具将您的资产文件夹包含在您的 jar 文件中。
Another way would be to use this same eclipse export wizard and check "Save as ANT script" and then edit the generated ant file to include all the files and folders needed by your app.
另一种方法是使用相同的 eclipse 导出向导并选中“另存为 ANT 脚本”,然后编辑生成的 ant 文件以包含应用程序所需的所有文件和文件夹。
Hope this helps
希望这可以帮助
回答by Kyrremann
This is an old question, but if you are using a new version of LibGDX and Gradle you can use the command line to make an executable.
这是一个老问题,但如果您使用的是新版本的 LibGDX 和 Gradle,您可以使用命令行来制作可执行文件。
There are several commands, but these are for packaging:
有几个命令,但这些是用于打包的:
Desktop
桌面
gradlew desktop:dist
Android (unsigned)
安卓(未签名)
gradlew android:assembleRelease
iOS
IOS
gradlew ios:createIPA
Web
网络
gradlew html:dist
Read more at https://github.com/libgdx/libgdx/wiki/Gradle-on-the-Commandline
在https://github.com/libgdx/libgdx/wiki/Gradle-on-the-Commandline阅读更多信息
回答by P.T.
I'm assuming your application is setup as the libgdx wiki page suggests(with a "main project" and separate "desktop" and "android" projects that share the sources from the "main" project).
我假设您的应用程序已按照 libgdx wiki 页面的建议进行设置(具有“主项目”和单独的“桌面”和“android”项目,它们共享来自“主”项目的源代码)。
Since your app is written in Java, it requires a JVM to run on a desktop. You have to decide if you want to package that up, or rely on a JVM already being installed by the user. I believe packaging up the JVM with Java class files is very complicated and raises a host of other issues (and it becomes very platform specific). So, I believe most libgdx-based games get distributed as an executable Jar file, which means the user must already have Java. (It works for Minecraft, so its probably good enough for you, too. :)
由于您的应用程序是用 Java 编写的,因此它需要一个 JVM 才能在桌面上运行。您必须决定是要将其打包,还是依赖于用户已安装的 JVM。我相信用 Java 类文件打包 JVM 非常复杂,并且会引发许多其他问题(并且它变得非常特定于平台)。因此,我相信大多数基于 libgdx 的游戏都是作为可执行 Jar 文件分发的,这意味着用户必须已经拥有 Java。(它适用于 Minecraft,所以它对你来说可能也足够了。:)
Eclipse makes that really easy: File -> Export ... -> Java -> Executable Jar File
. There may be additional steps required to include assets like your app's images and sounds into this .jar file. (My game is currently "asset free", so I don't have any experience with this part.)
Eclipse 让这一切变得非常简单:File -> Export ... -> Java -> Executable Jar File
. 可能需要执行其他步骤才能将应用程序的图像和声音等资产包含到此 .jar 文件中。(我的游戏目前是“无资产”的,所以我对这部分没有任何经验。)
You might also consider side-stepping the desktop executable, and packaging your game as an applet and running it in a web browser so there is very little "installation" required by the folks you want to show it to. Here's a walkthrough for making an applet from a libgdx-based game. (I haven't actually tried this myself yet, but I do have a libgdx-based game that I'm planning on doing this for.)
您还可以考虑绕过桌面可执行文件,将您的游戏打包为小程序并在 Web 浏览器中运行它,这样您想要向其展示的人几乎不需要“安装”。这是从基于 libgdx 的游戏制作小程序的演练。(我自己还没有真正尝试过,但我确实有一个基于 libgdx 的游戏,我打算为此做这个。)
回答by Thad.Nutting
If you're using Android Studio, you can create a custom configuration to distribute from within the program.
如果您使用的是 Android Studio,则可以创建自定义配置以从程序内进行分发。
On the Run dropdown list select edit configurations.
在运行下拉列表中选择编辑配置。
Click the "+". Select Gradle.
单击“+”。选择摇篮。
On the right half of that screen give your configuration a Name.
在该屏幕的右半部分,为您的配置命名。
Gradle Project: Use the browse button to select your desktop application. This will look something like (project name):desktop
Gradle 项目:使用浏览按钮选择您的桌面应用程序。这看起来像(项目名称):桌面
Tasks: type "desktop:dist"
任务:输入“桌面:dist”
Apply.
申请。
Close the configuration editor and select your new configuration from the dropdown. Hit run and it should build your project.
关闭配置编辑器并从下拉列表中选择您的新配置。点击运行,它应该构建您的项目。
Your new Jar file should be located in (ProjectName)/desktop/build/libs
你的新 Jar 文件应该位于 (ProjectName)/desktop/build/libs