

This article contains Java 9 module example using maven. In order to provide reliable configuration and strong encapsulation in a way that is both approachable to developers and supportable by existing toolchains, we treat modules as a fundamentally new kind of Java program component. A module is a named, self-describing collection of code and data. Its code is organized as a set of packages containing types, i.e., Java classes and interfaces; its data includes resources and other kinds of static information.
Table of Contents
Technology
- Java 9
- Maven 2.5
- Maven compiler plugin 3.6.0
Module Structure

module-maven-example
module declaration
A module’s self-description is expressed in its module declaration, a new construct of the Java programming language.
module-info.java
/** * Created by JavaDeveloperZone on 22-04-2017. */ module module.maven.demo { requires java.logging; }
Demo.java
package com.javadeveloperzone; import java.util.logging.Logger; /** * Created by JavaDeveloperZone on 22-04-2017. */ public class Demo { public static void main(String... args) { Logger logger=Logger.getLogger(Demo.class.getName()); logger.info("This is module demo using maven"); } }
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>module-demo</groupId> <artifactId>com.javadeveloperzone</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <configuration> <source>9</source> <target>9</target> <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> </configuration> </plugin> </plugins> </build> </project>
Build Project:
"C:\Program Files\Java\jdk-9\bin\java" -Dmaven.multiModuleProjectDirectory=F:\extrawork\java9-demo\module-maven-demo -Xmx2g -XX:ReservedCodeCacheSize=512m "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\lib\idea_rt.jar=65380:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.1 clean [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building com.javadeveloperzone 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ com.javadeveloperzone --- [INFO] Deleting F:\extrawork\java9-demo\module-maven-demo\target [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.170 s [INFO] Finished at: 2017-04-22T11:30:07+05:30 [INFO] Final Memory: 8M/28M [INFO] ------------------------------------------------------------------------ Process finished with exit code 0
Output:
INFO: This is module demo using maven
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.