如何为 Java 程序创建 .exe?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/516399/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:40:09  来源:igfitidea点击:

How do I create an .exe for a Java program?

javaexe

提问by Dónal

Possible Duplicate:
How can I convert my java program to an .exe file ?

可能重复:
如何将我的 java 程序转换为 .exe 文件?

I'd like to create a Windows .exe for a Java program. Previously, I've used JEXECreator for this, but it's not entirely satisfactory because:

我想为 Java 程序创建一个 Windows .exe。以前,我为此使用过 JEXECreator,但它并不完全令人满意,因为:

  • The executable sometimes works on the machine on which it was created but not on others.
  • The program is commercial; if you use the trial version, it adds a nag screen to your application.
  • 可执行文件有时可以在创建它的机器上运行,但不能在其他机器上运行。
  • 该计划是商业性的;如果您使用试用版,它会向您的应用程序添加一个唠叨屏幕。

I don't need the generated .exe to work if Java is not installed on the target machine (in fact, I think this is impossible).

如果目标机器上没有安装 Java,我不需要生成的 .exe 工作(事实上,我认为这是不可能的)。

Any recommendations?

有什么建议吗?

回答by Dónal

If Java is installed on the target machine, there is no need to create an .exe file. A .jar file should be sufficient.

如果目标机器上安装了 Java,则无需创建 .exe 文件。.jar 文件应该足够了。

回答by Jon Skeet

Launch4jperhaps? Can't say I've used it myself, but it sounds like what you're after.

Launch4j也许?不能说我自己用过它,但这听起来像你想要的。

回答by tonys

If you really want an exe Excelsior JET is a professional level product that compiles to native code:

如果你真的想要一个 exe Excelsior JET 是一个专业级的产品,它可以编译为本机代码:

http://www.excelsior-usa.com/jet.html

http://www.excelsior-usa.com/jet.html

You can also look at JSMooth:

你也可以看看 JSMooth:

http://jsmooth.sourceforge.net/

http://jsmooth.sourceforge.net/

And if your application is compatible with its compatible with AWT/Apache classpath then GCJ compiles to native exe.

如果您的应用程序与其兼容的 AWT/Apache 类路径兼容,则 GCJ 会编译为本机 exe。

回答by John T

Most of the programs that convert java applications to .exe files are just wrappers around the program, and the end user will still need the JRE installed to run it. As far as I know there aren't any converters that will make it a native executable from bytecode (There have been attempts, but if any turned out successful you would hear of them by now).

大多数将 java 应用程序转换为 .exe 文件的程序只是程序的包装器,最终用户仍需要安装 JRE 才能运行它。据我所知,没有任何转换器可以使其成为字节码的本机可执行文件(已经尝试过,但如果有任何成功,您现在会听到它们)。

As for wrappers, the best ones i've used (as previously suggested) are:

至于包装器,我用过的最好的(如前所述)是:

JSmooth

JSmooth

and

Launch4j

Launch4j

best of luck!

祝你好运!

回答by Greg Mattes

The Java Service Wrappermight help you, depending on your requirements.

Java服务包装可以帮助您,根据您的要求。

回答by Brandon DuRette

You could try exe4j. This is effectively what we use through its cousin install4j.

你可以试试exe4j。这实际上是我们通过其表亲install4j 使用的

回答by Forrest

I used exe4j to package all java jars into one final .exe file, which user can use it as normal windows application.

我使用 exe4j 将所有 java jar 打包成一个最终的 .exe 文件,用户可以将其用作普通的 Windows 应用程序。