Reputation: 21
I am new to JDK 9 and trying to use jlink to generate a runtime for a simple app.
I have the following module descriptors
module reader{
// no "requires" entries implies no dependency on other modules
// other modules can access org.reader package
// all other packages are implicitly unavailable
exports org.reader;
}
and
module decoder {
// depends on reader module
requires reader;
// exposes com.decoder package to modules which require decoder module
// all other packages in decoder module are implicitly unavailable to other modules
exports com.decoder;
}
I defined a couple of simple classes called Reader.java and Decoder.java, and am able compile and run them using the following steps.
(1) Download and unzip JDK and JRE 9.0.4 to a test directory
(2) Create the following directory structure inside the test directory.
/moduleExamples/readerDecoderExample/src/main/java
/moduleExamples/readerDecoderExample/src/main/java/reader
/moduleExamples/readerDecoderExample/src/main/java/decoder
(3) Add reader module-info.java, org/reader/Reader.java to reader directory. Add decoder module-info.java, com/decoder/Decoder .java to decoder directory.
(4) Navigate to test/moduleExamples/readerDecoderExample directory, run the following commands
export JAVA_HOME=test/jdk9.0.4 mkdir mods export MODULE_PATH=test/moduleExamples/readerDecoderExample/mods
(5) Compile reader and decoder modules
${JAVA_HOME}/bin/javac -d mods --module-source-path src/main/java/ $(find src/main/java -name "*.java")
(6) Run the Decoder class
${JAVA_HOME}/bin/java --module-path mods -m decoder/com.decoder.Decoder input.txt
(7) mkdir mlibs
(8) Package modules into jars using the following commands.
${JAVA_HOME}/bin/jar --create --file mlibs/[email protected] --module-version=1.0 -C mods/reader .
${JAVA_HOME}/bin/jar --create --file mlibs/decoder.jar --main-class=com.decoder.Decoder -C mods/decoder .
(9) At the end of step (8), I have a mlibs dir as shown below
readerDecoderExample/mlibs/decoder.jar
readerDecoderExample/mlibs/[email protected]
(10) When I try to build a JRE with the following command
${JAVA_HOME}/bin/jlink --module-path ${JAVA_HOME}/jmods;mlibs/[email protected] --add-modules [email protected] --output out
I get the following error.
Error: --output must be specified
Can somebody please tell me what I am doing wrong?
Thank you in advance!
Upvotes: 2
Views: 1349
Reputation: 51
Flag --output is an option and should be placed before --module-path flag.
Usage: jlink <options> --module-path <modulepath> --add-modules <module>[,<module>...]
In case of several module-path's - ':' delimiter was correct for me (Ubuntu).
Upvotes: 0
Reputation: 16
I came across the same problem on gitbash when I was doing a demo at work. I had tried it previously on a mac and the ${JAVA_HOME}/jmods;mlibs/[email protected]
works fine, just changing :
to ;
when moving to PC.
The error seemed to be around the jmods so I just removed it and it worked fine - not sure how or why, this approach doesn't work on the mac.
The following should work:
${JAVA_HOME}/bin/jlink --module-path mlibs/[email protected] --add-modules [email protected] --output out
Upvotes: 0