[英]How can I create a completely portable exe from a Java project?
My goal is simply to take my Java project (JDK 11, Javafx, non-modular, using Gradle in Intellij) and package into a single exe file. My goal is simply to take my Java project (JDK 11, Javafx, non-modular, using Gradle in Intellij) and package into a single exe file. No installer, no JRE required for the user.
用户无需安装程序,无需 JRE。 There are various packaging and exe creation tools, but I've yet to get one working the way I want to.
有各种打包和 exe 创建工具,但我还没有让一个按我想要的方式工作。
At first I tried javapackager but Inno Setup kept erroring.起初我尝试了 javapackager 但 Inno Setup 一直出错。 Then I managed to get launch4j working, but I found out a bit ago that there was no embedded JRE in that, so it couldn't run on computers without Java.
然后我设法让launch4j工作,但我不久前发现其中没有嵌入式JRE,所以它无法在没有Java的计算机上运行。 I also looked into jPackage but from what I've seen it only creates installers and I also had trouble setting it up.
我还研究了 jPackage,但据我所知,它只创建安装程序,而且我在设置它时也遇到了麻烦。 I ended up looping back to javapackager with the advice to use Inno Setup 5 instead of 6, and that worked, but the result was an installer, with seemingly no options either (at least by default)
我最终循环回到 javapackager 并建议使用 Inno Setup 5 而不是 6,这很有效,但结果是安装程序,似乎也没有选项(至少默认情况下)
Is what I want to achieve just not possible, even though it seems to me like it should be?我想要实现的目标是不可能的,即使在我看来它应该是这样吗? If so, what could be the closest I could achieve?
如果是这样,我能达到的最接近的可能是什么? The most important thing is for users to not have to worry about having Java installed, the rest of the stuff I can probably work with
最重要的是,用户不必担心安装了 Java,rest 我可能可以使用的东西
This works for me: Fristly, extract make your project to a .jar
- in IntelliJ you'd build
an artifact
.这对我有用:首先,将您的项目提取到
.jar
- 在 IntelliJ 中,您将build
一个artifact
。 When you got this .jar
-file, i can recommend the following things:当你得到这个
.jar
文件时,我可以推荐以下内容:
folder
, in which you perform all of these steps, so that all is neat and tidy .folder
,您可以在其中执行所有这些步骤,从而使一切变得整洁。project JRE
project JRE
.exe
.exe
的图标Now copy the icon for your .exe
, and the bin
- and lib
-folders of your JRE in another folder eg called "jre" in the folder(1).现在将
.exe
的图标以及 JRE 的bin
和lib
文件夹复制到另一个文件夹中,例如文件夹 (1) 中的“jre”。
The structure should look something like this: Folder->{icon.ico, jre ->{bin, lib}, yourProjectJar.jar}结构应如下所示:Folder->{icon.ico, jre ->{bin, lib}, yourProjectJar.jar}
When you have this done, download launch4j and run it.完成后,下载launch4j 并运行它。 In there (under Basic), it is mandatory to choose an output file with the
.exe
-extension and to choose the folder in which you put the bin
- and lib
-folders of your project jre.在那里(在 Basic 下),必须选择带有
.exe
扩展名的 output 文件,并选择放置项目 jre 的bin
和lib
文件夹的文件夹。 Non-Mandatory is to choose an icon for your .exe
- you can also find this under the Basic-Tab.非强制性是为您的
.exe
选择一个图标 - 您也可以在 Basic-Tab 下找到它。
The last mandatory step is to go to the JRE-Tab and insert the absolute path for eg called "jre" folder in which the bin
- and lib
-folder of your project jre are for "Bundled JRE paths".最后一个强制性步骤是将 go 插入 JRE-Tab 并插入绝对路径,例如名为“jre”的文件夹,其中项目 jre 的
bin
和lib
文件夹用于“捆绑的 JRE 路径”。 Then choose your Min JRE version (again, in the JRE-Tab) and make sure to have the drop-down to your right set to "Only use private JDK runtimes".然后选择您的 Min JRE 版本(同样,在 JRE-Tab 中)并确保将右侧的下拉菜单设置为“仅使用私有 JDK 运行时”。
Lastly, click on "Build Wrapper" (it's the fourth symbol looking from the left) and after choosing a place for your Manifest there you should have it.最后,单击“Build Wrapper”(它是从左侧看的第四个符号),在为您的 Manifest 选择一个位置之后,您应该拥有它。
Greets, JC问候,JC
PS: this should give you an .exe
with the JRE
of your project and is thus runnable on any System. PS:这应该为您提供一个带有项目
JRE
的.exe
,因此可以在任何系统上运行。 Congrats.恭喜。 You just used an advantage of Java compared to some other languages.
与其他一些语言相比,您刚刚使用了 Java 的优势。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.