"java --module" - Launching Program from Module JAR

This section provides a tutorial example on how to use 'java --module' command to launch a program that is packaged in a module JAR file.

You can also launch a program that is packaged in a module JAR file using the "java --module" command. You need to specify the JAR file in the module path.

For example, I have a program class called HelloModularized.java packaged in a Java module called com.herongyang. Here is the module class file directory structure generated by the above "javac" command:

C:\herong>tree /F .\cls
    |   module-info.class

Here is how I created a module JAR file by archiving the entire class file directory tree:

C:\herong>jar --create --verbose --file com.herongyang.jar 
   -C .\cls\com.herongyang .

added manifest
added module-info: module-info.class
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/herongyang/(in = 0) (out= 0)(stored 0%)
adding: com/herongyang/util/(in = 0) (out= 0)(stored 0%)
adding: com/herongyang/util/HelloModularized.class(in = 472) (out= 315)

Here is how I used the "java --module" command to launch my program from the module JAR file:

C:\hreong>java --module-path com.herongyang.jar
   --module com.herongyang/com.herongyang.util.HelloModularized 

Hello world! - Modularized

I can also use the "java --describe-module" command to print information from my module:

C:\herong>java --module-path com.herongyang.jar 
   --describe-module com.herongyang

com.herongyang file:///C:/herong/com.herongyang.jar
exports com.herongyang.util
requires java.base

Last update: 2018.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

java - The Java Program Launcher

 java - Program Launching Command and Options

 Launching Hello.java - My First Java Program

 "java -classpath" - Specifying Class Path

 "java -jar" - Specifying Executable JAR File

 "java -X" - Specifying Non-Standard Options

 "java --list-modules" - Listing Modules in JDK

 "java --describe-module" - Printing Module Definition

 "java --module" - Launching Program from Module

"java --module" - Launching Program from Module JAR

 javaw - Launching Java Programs without Console

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials


 Full Version in PDF/EPUB