java 9:JLink创建了无效图像 - 缺少模块可执行脚本 [英] java 9: JLink created invalid images - missing module executable script

查看:153
本文介绍了java 9:JLink创建了无效图像 - 缺少模块可执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含3个模块的示例应用程序 user dept account 。在我的用户模块中,我有一个主类,并使用以下命令编译我的模块:

I am creating a sample application with 3 modules user, dept and account. In my user module, I have a main class and compile my modules with the following command:

javac -d target --module-source-path src $(find -name "*.java")

编译完成后,执行以下命令运行命令:

After compiling, execute following command for run:

java -p target -m com.user/com.user.info.Launcher

运行java模块后的输出成功。但是当尝试使用 jlink 创建运行时映像时,映像已成功创建但模块可执行脚本不存在。为了创建图像,我使用以下命令:

The output after running java modules are successful. But when trying to create runtime image using jlink the image created successfully but module executable script is not there. For create an image, I am using the following command:

jlink --module-path $JAVA_HOME/jmods:target --add-modules com.user --output my-app

在运行时图像中,我有 bin 目录,但此目录仅包含 java 主题演示脚本。我也期待用户主类脚本,用于执行我的应用程序。

In, runtime image, I have bin directory, but this directory contains only java and keynote script. I am expecting user main class script as well, for executing my application.

我的Java版本如下:

My Java version as below:

java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+165)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+165, mixed mode)

如何解决此问题?

推荐答案

jlink 创建一个运行时VM映像,其中只包含所需的模块。

jlink creates a runtime VM image in which it includes only the modules that are needed.

由于您指定了 - add-modules com.user ,该图像将包含 com.user 模块,以及它(直接或间接)所依赖的所有模块。

Since you specified --add-modules com.user the image will include the com.user module, and all of the modules it (directly or indirectly) depends on.

您可以使用 java 运行您的应用程序生成的图像的 bin 文件夹中的二进制文件,并使用以下命令:

You can run your application by using the java binary in the bin folder of the generated image, and using the command:

java com.user.info.Launcher






你也可以 jlink 使用 - launcher< command&g生成一个启动器脚本t; =< module> /< main> 选项。在你的情况下你可以做类似的事情:


You can also have jlink generate a launcher script using the --launcher <command>=<module>/<main> option. In your case you could do something like:

jlink --module-path $JAVA_HOME/jmods:target --add-modules com.user --output my-app --launcher launch=com.user/com.user.info.Launcher

之后,您可以从 bin 目录中使用 launch 来运行该应用程序。

And after that, you can just use launch from the bin directory to run the application.

这篇关于java 9:JLink创建了无效图像 - 缺少模块可执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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