Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 769
Harmeet Singh Taara Avatar asked May 20 '17 11:05

Harmeet Singh Taara


1 Answers

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.

like image 143
Jorn Vernee Avatar answered Sep 21 '22 00:09

Jorn Vernee