捆绑JRE以及可执行jar

问题描述 投票:4回答:2

我想在我的可执行jar.so中捆绑JRE,这个exe可以在任何系统中运行。我已经尝试过lunch4j来创建捆绑的JRE,但我们需要运送JRE和exe两者。但根据我的要求,我不应该使用任何安装程序。我不应该在客户端机器中提取jre。请帮助有一种方法将JRE放入jar并使其使用。

java bundle exe
2个回答
6
投票

您不能将JRE放在JAR文件中。 (嗯,你可以......但它无济于事。)

您需要做的是构建和分发安装程序。创建安装程序的推荐方法是使用商业或开源安装程序生成器。 (谷歌会帮你找到一个。)

也可以在ZIP文件中嵌入JRE,如下所述:

ZIP文件包含JRE和应用程序JAR以及它需要的其他文件。用户必须解压缩ZIP文件才能安装该应用程序。


..但它正在复制几乎100 MB的客户端系统中的总JRE。是否可以使JRE重量轻?

并不是的。分发JRE的最(合法)轻量级方法是分发Oracle Java安装程序。请注意Java二进制许可证禁止分发减少的JRE。如果你想沿着那条路走下去,请先咨询律师!


使用嵌入式JRE分发Java应用程序可能是件坏事:

  • 它用多个JRE填满用户的磁盘。
  • JRE往往被隐藏起来/不可见于正常的安全更新/修补/审核。因此,他们往往成为担保责任。
  • 您需要定期更新您的可分发项目......以避免在毫无戒心的用户身上造成过时/不安全的JRE。

0
投票

迟到总比没有好。我在pom.xml中使用了maven-shade-plugin,如下所示:

        <plugin>
          <artifactId>maven-shade-plugin</artifactId>
          <version>2.4.3</version>
          <configuration>
              <transformers>
                  <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                  <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>${mainClass}</mainClass>
                  </transformer>
              </transformers>
              <!-- If false the shaded artifact takes the normal artifact name, such as,  "core-tools-1.0-SNAPSHOT.jar"-->
              <!-- Meanwhile, another non-shaded version takes the prefix Original, such as  "Original-core-tools-1.0-SNAPSHOT.jar"-->
            <shadedArtifactAttached>false</shadedArtifactAttached>
              <!-- Exclude signed Manifests from the UberJar -->
              <filters>
                  <filter>
                      <artifact>*:*</artifact>
                      <excludes>
                          <exclude>META-INF/*.SF</exclude>
                          <exclude>META-INF/*.DSA</exclude>
                          <exclude>META-INF/*.RSA</exclude>
                      </excludes>
                  </filter>
                  <filter>
                      <artifact>*:*</artifact>
                      <includes>
                          <include>sun/misc/**</include>
                      </includes>
                  </filter>
              </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.