Dockerizing Multi-maven project with docker-compose.yml
I have a problem with a docker-compose on my maven-multi project. My module won't start up on docker and the container throws an exception:
Exception in thread "main" java.lang.NoClassDefFoundError:
my parent pom:
<?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>org.example.com</groupId>
<artifactId>derived-markets</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.example.com</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
</parent>
<properties>
<java.version>11</java.version>
<lombok.version>1.18.12</lombok.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
<modules>
<module>model</module>
<module>saver-module</module>
<module>testing-tool-module</module>
</modules>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.3</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
this is my module pom:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example.com</groupId>
<artifactId>derived-markets</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>saver-module</artifactId>
<name>saver-module</name>
<description>Database saver</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupIdorg.example.com</groupId>
<artifactId>model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>org.example.com.SaverModuleApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<finalName>saver-module</finalName>
</build>
</project>
my docker-compose.yml is like this:
version: "3"
services:
saver:
build:
context: ./saver-module
dockerfile: Dockerfile
ports:
- "8090:8090"
and actually its dockerfile inside the module:
FROM maven:3.6.0-jdk-11-slim AS build
ADD src /derived2/saver-module/src
ADD pom.xml /derived2/saver-module
RUN mvn -f /derived2/saver-module/pom.xml clean install
FROM openjdk:latest
ADD target/saver-module.jar /saver-module.jar
EXPOSE 8090
CMD ["java", "-jar", "saver-module.jar"]
No comments:
Post a Comment