java 9: JLink created invalid images - missing module executable script

会有一股神秘感。 提交于 2019-12-21 04:42:22

问题


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

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

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.

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)

How can I resolve this problem?


回答1:


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

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.

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

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

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



来源:https://stackoverflow.com/questions/44085367/java-9-jlink-created-invalid-images-missing-module-executable-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!