简体   繁体   English

使用捆绑的 jre 运行 java 安装程序

[英]running java installer with bundled jre

We currently ship a java(jar) installer of our application.我们目前提供应用程序的 java(jar) 安装程序。 Taking into acount the changes to jdk11 we want our users to have the same easy install experience.考虑到 jdk11 的变化,我们希望我们的用户拥有同样简单的安装体验。 So, what we are looking for, is to have just one file that can be run even if there is no java installed, it should just start our old java installer.所以,我们正在寻找的是,即使没有安装 java,也只有一个可以运行的文件,它应该只是启动我们旧的 java 安装程序。

Probably, this means that we jave to bundle the jre and have a script that runs the jar, but the problem is how to run the batch file natively ?可能,这意味着我们要打包 jre 并有一个运行 jar 的脚本,但问题是如何在本地运行批处理文件? We need this to work on Windows and Mac.我们需要它在 Windows 和 Mac 上工作。 Most tools we are looking into require java to run the wrapped jar.我们正在研究的大多数工具都需要 java 来运行包装好的 jar。

You have to build 2 different scripts/installers, one for each platform.您必须构建 2 个不同的脚本/安装程序,每个平台一个。 Even looking at very popular software like Chrome, the platform choice is still there (even though you're usually directed to the correct choice based on the information your browser provides them with)即使查看 Chrome 等非常流行的软件,平台选择仍然存在(即使您通常会根据浏览器提供的信息定向到正确的选择)

Depending on how much time you can put in this task, the quickest (and dirtiest) solution would be having an archive for each platform that contains the script .bat for Windows and .sh for OS X together with the jre (also different per platform), ask the user to unarchive and run the script which will run your jar with the packed jre.根据您可以在此任务中投入多少时间,最快(也是最脏)的解决方案是为每个平台创建一个存档,其中包含用于 Windows 的脚本.bat和用于 OS X 的.sh以及jre (每个平台也不同) ),要求用户取消归档并运行脚本,该脚本将使用打包的 jre 运行您的 jar。 Otherwise, you'll need to create an MSI/exe for windows and a dmg (or other installer type) for MacOs.否则,您需要为 Windows 创建一个MSI/exedmg创建一个dmg (或其他安装程序类型)。

I have done the dmg before with a bundled jre and can try to look for the details if you need them (I no longer have access to the code but can probably find the details).我之前使用捆绑的 jre 完成了 dmg,如果需要,可以尝试查找详细信息(我不再访问代码,但可能可以找到详细信息)。 It was a free solution but it did require an OS X computer to create the dmg .这是一个免费的解决方案,但它确实需要一台 OS X 计算机来创建dmg

One option that I used before and works very well is install4j but the price is not small.我以前使用过并且效果很好的一个选项是install4j,但价格不小。

LE: Self contained packaging - although I haven't used this before, it seems like the best current option for your problem. LE: 独立包装——虽然我以前没有用过这个,但它似乎是解决你问题的最佳选择。

And an open source option - packr .还有一个开源选项——packr

that Self Contained packaging doesn't really help, same for packr, same for launch4j.自包含包装并没有真正的帮助,packr 也是一样,launch4j 也是如此。 Because all those just generate a application image with a lot of files and directories.因为所有这些只是生成一个包含大量文件和目录的应用程序映像。

Problem is before that, as an installer you want 1 big exe (or dmg for mac) that does it all, single click We are already at the stage like SCP or Packr.问题是在此之前,作为安装程序,您需要 1 个大 exe(或 mac 的 dmg)来完成所有工作,单击我们已经处于像 SCP 或 Packr 这样的阶段。 Because that is easy or current installer.exe and jre\\ sub dir and a batch/sh file besides it.因为这很容易或当前 installer.exe 和 jre\\ sub dir 以及除此之外的批处理/sh 文件。 Problem is how to get from that directory structure to a single exe that runs.问题是如何从该目录结构获取运行的单个 exe。

So what we should have is something that can zip that in a self extracting archive, when clicking on that it should auto extract to the temp dir of the OS, then run directly a command on it (like a batch file or directly in that extracted dir: .\\jre\\bin\\javaw.exe -jar installler.jar) But nobody seems to have made such a thing, the closest that we have is eclipse with Oomph:所以我们应该拥有的是可以将其压缩到自解压存档中的东西,当单击它时它应该自动解压到操作系统的临时目录,然后直接在其上运行命令(如批处理文件或直接在提取的dir: .\\jre\\bin\\javaw.exe -jar installler.jar) 但似乎没有人做过这样的事情,我们最接近的是带有 Oomph 的 eclipse:

[1] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor/src/extractor.c [1] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor/src/extractor.c

[2] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor.lib/src/org/eclipse/oomph/extractor/lib/BINExtractor.java [2] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor.lib/src/org/eclipse/oomph/extractor/lib /BINEExtractor.java

problem is a bit that is doing the extracting through java and still wants a vm first.问题是通过java进行提取并且仍然首先需要一个vm。

There is a new tool being developed for that: jpackage 为此,正在开发一种新工具:jpackage

If your project is build using Gradle then you can easily use the Badass jlink plugin: https://github.com/beryx/badass-jlink-plugin to build an installer / package using jpackage with a bundled JVM 如果您的项目是使用Gradle构建的,那么您可以轻松使用Badass jlink插件: https : //github.com/beryx/badass-jlink-plugin使用带有绑定的JVM的jpackage来构建安装程序/软件包

Here's an article how to build an app image using OpenJDK 11 and using OpenJDK 14 with jpackage only for building the installer / package: https://walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-using-jlink-and-jpackage 这是一篇文章,介绍如何使用OpenJDK 11和带有jpackage的OpenJDK 14构建应用程序映像,仅用于构建安装程序/软件包: https : //walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-使用jlink和jpackage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM