简体   繁体   English

如何将JRE与Launch4j捆绑在一起?

[英]How to bundle a JRE with Launch4j?

I have Launch4J on my computer and it's a great program. 我的计算机上有Launch4J,这是一个很棒的程序。 One of its features I'm interested in is the ability to bundle a JRE in the general .EXE file. 我感兴趣的一个功能是能够在一般.EXE文件中捆绑JRE。 However, I can't find any documentation that describes how to go about doing this. 但是,我找不到任何描述如何执行此操作的文档。

How do I bundle a JRE with the EXE? 如何将JRE与EXE捆绑在一起? Plus, where do I get a compact, portable JRE to run? 另外,我在哪里可以运行紧凑的便携式JRE? The download links on Oracle are for the installer packages. Oracle上的下载链接用于安装程序包。

After some attempts i finally get a workaround to bundle the jre in my application: 经过一些尝试后,我终于得到一个解决方法,将jre捆绑在我的应用程序中:

I package my app as a zip file with the following folders inside: 我将我的应用程序打包为zip文件,其中包含以下文件夹:

containerFolder
|- jre
      |-bin (in bin there is java.exe)
      |-lib
|- cfg (to save the user configuration, but it's not needed)
|- bin (my application with the .exe and the .jar and all the other stuff)

In the xml file of launch4j i configure the jre like this: 在launch4j的xml文件中我配置jre,如下所示:

<jre>
    <path>../jre</path>
    <opt>-DgvSIG.confDir=../cfg</opt>
</jre>

The trick here is that the path is not to the java.exe file. 这里的诀窍是路径不是java.exe文件。 The path to the jre is relative to the position of the .exe and it should point to one folder before the java.exe file jre的路径是相对于.exe的位置,它应该指向java.exe文件之前的一个文件夹

The jre folder i'm using is just a copy&paste from the jre folder installed on a windows system. 我正在使用的jre文件夹只是从安装在Windows系统上的jre文件夹中复制和粘贴。

The same problem like you mate. 像你交配一样的问题。 No worries now. 现在不用担心。 Its all solve with the maximum depth to solve future solution. 它全部解决了最大深度,以解决未来的解决方案。 Solution how you can bundle your JRE for your jar without the need that the user has to install java or not. 解决方法如何在不需要用户安装java的情况下为您的jar捆绑JRE Your java application will run. 您的Java应用程序将运行。

  1. Copy lib and bin folder from your JRE folder to your project dist folder libbin文件夹从JRE文件夹复制到项目dist文件夹

jar转exe

  1. open launch4j and enter the following setting. 打开launch4j并输入以下设置。 在此输入图像描述

The trick is you need to give the full path to the including javaw.exe. 诀窍是你需要提供包含javaw.exe的完整路径。

Enjoy!!!! 请享用!!!!

I did the following and it worked for me using ver Launch4j 3.11: 我做了以下操作,它使用ver Launch4j 3.11为我工作:

  1. Created a new folder for my application (called for example MyApp). 为我的应用程序创建了一个新文件夹(称为MyApp)。
  2. Copied the jar file from the java project dist folder to the MyApp along with the lib folder. 将jar文件从java项目dist文件夹复制到MyApp以及lib文件夹。
  3. Created a folder called jre in my application folder MyApp so now MyApp folder contains: 在我的应用程序文件夹MyApp中创建了一个名为jre的文件夹,所以现在MyApp文件夹包含:
    • MyApp.jar MyApp.jar
    • lib <- this has the libraries needed by my java app. lib < - 这有我的java应用程序所需的库。
    • jre JRE
  4. Copied the bin and lib folders from java jre folder (C:\\Program Files (x86)\\Java\\jre7) to MyApp\\jre 将bin和lib文件夹从java jre文件夹(C:\\ Program Files(x86)\\ Java \\ jre7)复制到MyApp \\ jre
  5. In the Launch4j having set all the required options, then set the Bundled JRE path to "jre" 在Launch4j中设置了所有必需的选项,然后将Bundled JRE路径设置为“jre”

    Launch4j JRE选项

  6. Make sure that in the search options "Only use private JDK runtimes" is selected. 确保在搜索选项中选择“仅使用私有JDK运行时”。

I have just done this. 我刚做完了 Above clearly describe the method for bundling jre. 以上清楚地描述了捆绑jre的方法。

Here, I just share an experience that I have struggled. 在这里,我只是分享一些我一直在努力的经历。 If you want to create an installer exe after created wrapper exe by launch4j, pay attention to the file path for launch4j and jre. 如果要在launch4j创建包装器exe之后创建安装程序exe,请注意launch4j和jre的文件路径。 This is my path I used to solve my issues: 这是我用来解决问题的途径:

launch4j, bin/jre, resources/bin/jre. launch4j,bin / jre,resources / bin / jre。

launch4j, bin, and resources are at same level. launch4j,bin和资源处于同一级别。

A working example of using Launch4J to bundle a Java application with a specific JRE can be found at https://github.com/vZome/vzome/blob/master/desktop/platform/windows/README.md . 可以在https://github.com/vZome/vzome/blob/master/desktop/platform/windows/README.md找到使用Launch4J将Java应用程序与特定JRE捆绑在一起的工作示例。 This particular distribution is configured to require vZome to use the bundled JRE rather than any JRE found on the target platform. 此特定分发配置为要求 vZome使用捆绑的JRE而不是目标平台上的任何JRE。

Hope this helps. 希望这可以帮助。

The jre can usually be found in your SDK folder. jre通常可以在SDK文件夹中找到。 Yes the links online are installers, but once it installs, the JRE is now located on your local disk. 是的在线链接是安装程序,但安装后,JRE现在位于本地磁盘上。 Mine is located in 我的位于

${jdk folder}\jre

The parts that you don't need from the JRE could probably be removed manually if you really wanted (I'm not sure whats available online). 如果您真的想要,可能会手动删除JRE中不需要的部件(我不确定在线是否可用)。

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

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