windows 如何为您的 Java 应用程序创建本机二进制文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5869665/
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 create native binaries for your Java app?
提问by Ariejan
I'm wondering how to package a Java application into a native binary for Windows, Linux and Mac OS X.
我想知道如何将 Java 应用程序打包成适用于 Windows、Linux 和 Mac OS X 的本机二进制文件。
I know Minecraft does this, but I can't figure out how. This is what'd I'd like to do:
我知道 Minecraft 会这样做,但我不知道怎么做。这就是我想要做的:
- From NetBeans (preferably) or Eclipse, build the three binaries automatically.
- Include native libraries for OpenGL et. all.
- Obfuscate my code if possible.
- 从 NetBeans(最好)或 Eclipse,自动构建三个二进制文件。
- 包括用于 OpenGL 等的本机库。全部。
- 如果可能,混淆我的代码。
If there's some way to mimic the Minecraft auto-updater feature, that'd be totally awesome.
如果有某种方法可以模仿 Minecraft 的自动更新功能,那就太棒了。
So, are there any tools available to do this for you, or do I need to write a large bulk of XML to accomplish this?
那么,是否有任何工具可以为您执行此操作,或者我是否需要编写大量 XML 来完成此操作?
采纳答案by Lawrence McAlpin
To make a native binary for Windows, you would use a tool like Launch4J. On OSX you could use JarBundler. Minecraft simply distributes the jar file for Linux. I'm not aware of a native binary packager for Linux.
要为 Windows 制作本机二进制文件,您可以使用Launch4J 之类的工具。在 OSX 上,您可以使用JarBundler。Minecraft 只是为 Linux 分发 jar 文件。我不知道 Linux 的本机二进制打包程序。
You could also compile your Java code via GCJ but that's probably not what you want, as there are limitations and compatibility concerns there. The native bundlers like Launch4j and JarBundler simply wrap your jar file and use a real JRE to execute it.
您也可以通过 GCJ 编译您的 Java 代码,但这可能不是您想要的,因为那里存在限制和兼容性问题。像 Launch4j 和 JarBundler 这样的原生打包器只是简单地包装你的 jar 文件并使用真正的 JRE 来执行它。
As for integrating with NetBeans or Eclipse, you'll probably have to write your own ant build file, especially since the solution varies from one platform to the next.
至于与 NetBeans 或 Eclipse 的集成,您可能必须编写自己的 ant 构建文件,尤其是因为解决方案因平台而异。
回答by Anthony O.
If you are using Java 9, you can also use Java 9 Modularization & jlink
to ship a zero-dependency native app.
如果您使用的是 Java 9,您还可以使用 Java 9 Modularization &jlink
来发布零依赖本机应用程序。
There is also maven-jlink-plugin
that could help here.
这里也maven-jlink-plugin
有帮助。
回答by Suresh Kumar
Take a look at GCJBuilder pluginfor eclipse. Not sure if it supports cross compilation as the command GCJcompiler does.
看看Eclipse 的 GCJBuilder 插件。不确定它是否像命令GCJ编译器那样支持交叉编译。
回答by Andrew Thompson
If the app. has a GUI and can be distributed from a web site, look into Java Web Start. JWS is supplied by Oracle, and provides auto-update amongst many other features.
如果应用程序。有一个 GUI 并且可以从网站分发,请查看Java Web Start。JWS 由 Oracle 提供,并在许多其他功能中提供自动更新。
Note that JWS uses Jar files, so no conversion is necessary.
请注意,JWS 使用 Jar 文件,因此不需要转换。
回答by Jeroen Baert
I've used JSMooth for this in the past: http://jsmooth.sourceforge.net/As mentioned before, this wrapper just looks for a real JRE to run it - it does not come with a bundled JRE.
我过去曾为此使用过 JSMooth:http://jsmooth.sourceforge.net/ 如前所述,这个包装器只是寻找一个真正的 JRE 来运行它——它没有附带捆绑的 JRE。