I've a project that has three modules: A, B and COMMON. I would like to put the common logic inside the COMMON module (the model for example), and then the two other modules with a dependency to it.
The two modules (A, B) will be build separately to create two different jars.
I'm testing it trying to put the log dependency inside the COMMON module, and then build the A project. It will build correctly but if I try to run the jar with "java -jar a.jar" it fails with a NoClassDefFound:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
The root pom:
<modules>
<module>common</module>
<module>a</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
</dependencyManagement>
The common pom:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
and the a pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>bla.bla.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>bla.blu</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>