2
I am adapting the exercise of the book "Java 9 - Interactive, reactive and modularized - author Rodrigo Turini" to a modular Maven project with java 10 modular. However when running, you are not finding the project’s java modules
~/AmbienteDeDesenvolvimento/Projetos/Cursos/Java9/bookstore $ java -jar app/target/app-1.0.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: br/com/casadocodigo/http/Books
at br.com.casadocodigo.MainMavenModulo.main(MainMavenModulo.java:17)
Caused by: java.lang.ClassNotFoundException: br.com.casadocodigo.http.Books
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 1 more
pom from the parent project
<?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>br.com.casadocodigo</groupId>
<artifactId>bookstore</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>domain</module>
<module>http</module>
<module>nf</module>
<module>app</module>
</modules>
<properties>
<java.version>10</java.version>
<start-class>br.com.casadocodigo.MainModulo</start-class>
<maven-compiler-pluging.version>3.7.0</maven-compiler-pluging.version>
<start-class>br.com.casadocodigo.MainMavenModulo</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-pluging.version}</version>
<configuration>
<source>10</source>
<target>10</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${start-class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom from the Domain project
<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>
<parent>
<groupId>br.com.casadocodigo</groupId>
<version>1.0.0</version>
<artifactId>bookstore</artifactId>
</parent>
<artifactId>domain</artifactId>
<packaging>jar</packaging>
</project>
pom of the http project
<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>
<parent>
<groupId>br.com.casadocodigo</groupId>
<version>1.0.0</version>
<artifactId>bookstore</artifactId>
</parent>
<artifactId>http</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>br.com.casadocodigo</groupId>
<artifactId>domain</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
pom from the nf project
<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>
<parent>
<groupId>br.com.casadocodigo</groupId>
<version>1.0.0</version>
<artifactId>bookstore</artifactId>
</parent>
<artifactId>nf</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>br.com.casadocodigo</groupId>
<artifactId>domain</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
app design pom
<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>
<parent>
<groupId>br.com.casadocodigo</groupId>
<version>1.0.0</version>
<artifactId>bookstore</artifactId>
</parent>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>br.com.casadocodigo</groupId>
<artifactId>domain</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>br.com.casadocodigo</groupId>
<artifactId>http</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>br.com.casadocodigo</groupId>
<artifactId>nf</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
Each project has its module-info.java Goes below.
module-info Domain
module domain {
exports br.com.casadocodigo.domain;
}
module-info http
module http {
exports br.com.casadocodigo.http;
requires domain;
requires jdk.incubator.httpclient;
}
module-info nf
module nf {
exports br.com.casadocodigo.service;
exports br.com.casadocodigo.model;
requires domain;
}
module-info app
module app {
exports br.com.casadocodigo;
requires domain;
requires http;
requires nf;
}
continues
For those who want to see the code in full, the same is in my github https://github.com/marcelosartor/Estudo-Java10_Modular-Com-Maven_Modular