在未安装 JRE 的情况下,在 Windows 中将 Java 程序作为 exe 运行

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

Running a java program as an exe in Windows without JRE installed

javawindows

提问by siva

I want to run a java program as an exe in Windows. The windows box doesn't install java at all...

我想在 Windows 中将 java 程序作为 exe 运行。windows盒子根本不安装java...

So, is there any other way in which the java program can be converted to an exe which removes the need for a dependency on the JRE?

那么,有没有其他方法可以将 java 程序转换为 exe,从而消除对 JRE 的依赖?

采纳答案by Vanya

You can use Excelsior JET compiler for that purpose.

为此,您可以使用 Excelsior JET 编译器。

See http://www.excelsiorjet.com/for more information on this.

http://www.excelsiorjet.com/了解更多信息。

回答by Sesh

For the application to run you will need the runtime. In fact the very first thing that happens when you start the app is a call is a made to OS to start JRE. You cannot do without JRE.

要运行应用程序,您将需要运行时。事实上,当你启动应用程序时发生的第一件事就是调用操作系统来启动 JRE。你不能没有 JRE。

[You can of course embded JRE into your app itself if you want].

[如果需要,您当然可以将 JRE 嵌入到您的应用程序中]。

回答by Cinder6

GCJcan create native code from Java source files. Here'sa tutorial on how to build it in Windows.

GCJ可以从 Java 源文件创建本机代码。 这是有关如何在 Windows 中构建它的教程。

回答by Andreas Dolk

You can ship the JRE with your application and use that JRE for your application. The effect is the same: The application will be started through an executable (wrapper needed) or script (batch) file and the target machine does not need to have a java runtime installed.

您可以随应用程序一起提供 JRE,并将该 JRE 用于您的应用程序。效果是一样的:应用程序将通过一个可执行文件(需要包装器)或脚本(批处理)文件启动,目标机器不需要安装 java 运行时。

Java doesn't have to be 'installed', it just has to be 'present'.

Java 不必“安装”,它只需要“存在”

回答by Thorbj?rn Ravn Andersen

I have used JSmooth to exify my application. It also allows for embedding a JRE inside. I just used the "ensure that at least Java X is available".

我已经使用 JSmooth 来验证我的应用程序。它还允许在内部嵌入 JRE。我只是使用了“确保至少有 Java X 可用”。

GPL, can be run as an ant task.

GPL,可以作为蚂蚁任务运行。

回答by Yuval

Have you tried install4j? There are various versions, some free, of this concept. Basically, this application compiles your application into an executable installer, specific to the OS of your choice.

你试过install4j吗?这个概念有各种版本,有些是免费的。基本上,此应用程序将您的应用程序编译为可执行安装程序,特定于您选择的操作系统。

回答by Yuval

回答by Baccata

Well given the fact, that you are requesting an executable file (exe) in Windows, there is another approach:

鉴于您在 Windows 中请求可执行文件 (exe) 的事实,还有另一种方法:

Use IKVM.NET - Bytecode Compilerwhich converts Java bytecode to .NET dll's and exe's.

使用IKVM.NET - 字节码编译器,它将 Java 字节码转换为 .NET dll 和 exe。

Get the latest version of IKVM.NET here.

此处获取最新版本的 IKVM.NET 。

Use this command

使用这个命令

 ikvmc -target:exe -out:foo.exe yourJarFile.jar

to create your .NET executable file.

创建您的 .NET 可执行文件。

After this, you can use your exe with the mandatory IKVM dll's or if you prefer one exe file, you can use ILMergein order to get a single executable file:

在此之后,您可以将您的 exe 与强制 IKVM dll 一起使用,或者如果您更喜欢一个 exe 文件,您可以使用ILMerge以获得单个可执行文件:

ILMerge.exe /target:winexe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1" /out:C:\foo\bar.exe foo.exe <IKVM dll's>.dll