Skip to content

gauthamkrishnanibm/modules-jlink-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 

Repository files navigation

Sample to demonstrate modules and jlink

Requires Java 9 or above. IBM Semueru Runtimes Java can be obtained here .

Environment Setup

To run this sample, first download zip or clone this repo - to clone:

git clone [email protected]:gauthamkrishnanibm/modules-jlink-sample.git

From inside the modules-jlink-sample directory,

Step 1: Compile the classes

javac -d mods/com.foo.bar/ com.foo.bar/module-info.java com.foo.bar/com/foo/bar/HelloWorld.java

Step 2: Create jar file

mkdir mlib
jar --create --file=mlib/com.foo.bar.hello.jar --module-version=0.0.1 --main-class=com.foo.bar.HelloWorld -C mods/com.foo.bar/ .

Step 3: Test the JAR file to make sure that it’s working

java --module-path=mlib --module=com.foo.bar

output:

INFO: Hello World!
java --module-path=mlib --describe-module com.foo.bar

output:

[email protected] file:///helloworld_jlink/mlib/com.foo.bar.hello.jar
requires java.base mandated
requires java.logging
contains com.foo.bar

Step 4: Creating a custom runtime image using jlink

jlink --module-path=$JAVA_HOME/jmods:mlib --add-modules=com.foo.bar --output=testRuntimeImage --strip-debug --no-header-files
contains com.foo.bar

step 5: Running the application from the custom runtime image

./testRuntimeImage/bin/java --module com.foo.bar

output:

INFO: Hello World!

step 6: Checking only the bare minimum modules have been added

./testRuntimeImage/bin/java --list-modules com.foo.bar

output:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages