Issue
I'm trying to create an image from my Spring Boot project and I want to create a Dockerfile, that can create an image of my project.
After a few Google searches, I came across this tutorial from the official documentation.
So I tried to create a file based on it and this is what I got:
FROM openjdk:17-jdk-alpine
COPY out/artifacts/DWH_WebServices_jar/DWH_WebServices.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
But when running the DockerFile with Intellij, I get this error:
Error: Could not find or load main class com.business.dwh_webservices.DwhWebServicesApplication
Caused by: java.lang.ClassNotFoundException: com.business.dwh_webservices.DwhWebServicesApplication
So I thought that maybe I was misinforming my class when creating the .JAR, but I did it correctly :
My class exist as you can see here :
And here is my 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.business</groupId>
<artifactId>dwh-webservices</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>DWH_WebServices</name>
<description>DWH_WebServices</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.25.0-GA</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
What am I doing wrong ?
Solution
I used mvn package
and it worked !
Thanks to @SimonMartinelli.
Answered By - Louis Chopard
Answer Checked By - Willingham (JavaFixing Volunteer)