Java Tools Tutorials - Herong's Tutorial Examples - v6.23, by Herong Yang
"javac --module" - Compiling Entire Module
This section provides a tutorial example on how to use 'javac --module' command to compile all Java source code in an entire module.
If your Java program is packaged in a Java module (which was introduced in Java 9 in 2017), you can compile all Java source files in the module using the "javac --module" command.
Here is the source file directory structure of a simple Java module called "com.herongyang":
herong> tree /F .\src .\SRC |---com.herongyang | module-info.java | |---com |---herongyang |---util HelloModularized.java
The module-info.java source code is shown below:
/* module-info.java * Copyright (c) 2018 HerongYang.com. All Rights Reserved. */ module com.herongyang { requires java.base; exports com.herongyang.util; }
The HelloModularized.java source code is shown below:
/* HelloModularized.java * Copyright (c) 2018 HerongYang.com. All Rights Reserved. */ package com.herongyang.util; public class HelloModularized { public static void main(String[] a) { System.out.println("Hello world! - Modularized"); } }
In order compile all Java source files in a given module, we actually need 3 options:
In my case, I used the following command to compile my module "com.herongyang":
herong> javac --module com.herongyang -d .\cls --module-source-path .\src
Here is the module output file directory structure:
herong> tree /F .\cls .\CLS |---com.herongyang | module-info.class | |---com |---herongyang |---util HelloModularized.class
I can run the HelloModularized.java program from the module now:
herong> java --module-path .\cls \ --module com.herongyang/com.herongyang.util.HelloModularized Hello world! - Modularized
Of course, I can put my module output files into a JAR file for distribution. See JAR tutorials in this book for more details.
Table of Contents
►javac - The Java Program Compiler
javac - Java Compilation Command and Options
Compiling Hello.java - My First Java Program
"javac -classpath" - Specifying Class Path
"javac -verbose" - Printing Compilation Details
"javac -sourcepath" - Specifying Source Path
"javac -d" - Specifying Output Directory
Two Types of "import" Statements
"import" Statements Processed by "javac"
"javac -g" - Controlling Debugging Information
►"javac --module" - Compiling Entire Module
"javac -X" - Specifying Non-Standard Options
java - The Java Program Launcher
jpackage - Binary Package Builder
javadoc - The Java Document Generator
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
jrunscript - Script Code Shell
native2ascii - Native-to-ASCII Encoding Converter