我试图从我的Sping Boot 项目创建一个映像,我想创建一个Dockerfile,它可以创建我的项目的映像。
经过几次谷歌搜索,我从官方文档中找到了这个教程。
所以我试着创建一个基于它的文件,这是我得到的:
FROM openjdk:17-jdk-alpine
COPY out/artifacts/DWH_WebServices_jar/DWH_WebServices.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
但是当使用Intellij运行DockerFile时,我收到以下错误:
Error: Could not find or load main class com.business.dwh_webservices.DwhWebServicesApplication
Caused by: java.lang.ClassNotFoundException: com.business.dwh_webservices.DwhWebServicesApplication
所以我想,在创建.JAR时,我可能给类提供了错误的信息,但我做得很正确:
我的类存在如下所示:
这是我的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>
我做错了什么?
1条答案
按热度按时间wn9m85ua1#
我用了
mvn package
,它起作用了!感谢@西蒙·马蒂内利。