Java内置的自包含应用程序 [英] Self-Contained Applications, built in Java

查看:179
本文介绍了Java内置的自包含应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过一些在线演示,它们简要地提到了Java 9中的独立应用程序,但是我有一个问题需要解决.

I've watched a few online presentations that briefly mentioned self-contained applications in Java 9, but I have a question that I would like cleared up.

使用新的模块系统,现在只允许包含运行应用程序所需的最少代码量.但是,希望运行该应用程序的系统是否仍然需要JRE,或者该程序的基本模块中可以包含某些内容?

With the new module system, you're now allowed to only include the minimum amount of code required to run your application. However, does the system that wishes to run the application still require the JRE, or is that something that can be included in the base module within the program?

我怀疑是后者,因为页面(此处)下载Java的最新版本仍显示版本8_151.

I suspect it's the latter, as the page (here) to download the newest version of Java still shows version 8_151.

TL; DR-使用Java 9,是否可以创建一个自包含的可执行文件,该文件可以在未安装JRE/Java的系统上执行?

TL;DR - Using Java 9, is it possible to create a self-contained executable that can be executed on a system without the JRE/Java installed?

推荐答案

jlink

是的,这是可能的 JEP 282 )一起使用,但所有您的代码您的依赖项必须是模块化的JAR(即具有module-info.class的JAR).它是这样的:

jlink

Yes, this is possible with jlink (JEP 282), but all of your code and your dependencies need to be modular JARs (i.e. ones with module-info.class). It works like this:

jlink
    --module-path $JAVA_HOME/jmods:mods
    --add-modules your.app
    --launcher launch-app=your.app
    --output your-app-image

详细信息:

  • --module-path列出了包含模块的文件夹-这需要包括您要使用的JDK(在$JAVA_HOME/jmods中)和您的应用程序模块(mods)
  • 附带的平台模块.
  • --add-modules命名您希望运行时映像包含的模块-包括其所有(传递)依赖项
  • --launcher是可选的,但非常方便;它使用给定名称(launch-app)创建一个特定于操作系统的启动器(例如Windows上的.bat),该启动器启动指定的模块(your.app;在这种情况下,假定为其定义了主类)
  • --output指定在何处创建运行时映像
  • --module-path lists the folders that contain modules - this needs to include the platform modules shipped with the JDK you want to use (in $JAVA_HOME/jmods) and your application modules (mods)
  • --add-modules names the module(s) that you want your runtime image to contain - all of its (their) transitive dependencies are included
  • --launcher is optional, but very handy; it creates an OS-specific launcher (e.g. a .bat on Windows) with the given name (launch-app) that launches the specified module (your.app; in this case assuming the main class is defined for it)
  • --output specifies where to create the runtime image

这篇关于Java内置的自包含应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆