我想在docker中启动我的spring-boot应用程序,但在docker run
中出现错误
我的主类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.emo.test</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<artifactId>test-core</artifactId>
<version>${parent.version}</version>
<packaging>jar</packaging>
<name>test-core</name>
<url>http://maven.apache.org</url>
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.test.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的货单:
Manifest-Version: 1.0
Built-By: emo.leumassi
Build-Jdk: 11.0.7
Main-Class: com.test.Application
Created-By: Apache Maven
由于某些原因,我不想使用spring-boot-maven-plugin
我的Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=test-*.jar
COPY ${JAR_FILE} test.jar
ENTRYPOINT ["java", "-jar", "test.jar"]
我用这个脚本创建了容器:
docker build -t test .
docker run -p 8080:8080 test
我得到这个错误:
Sending build context to Docker daemon 18.94kB
Step 1/4 : FROM openjdk:8-jdk-alpine
---> a3562aa0b991
Step 2/4 : ARG JAR_FILE=test-*.jar
---> Running in 739ab5566b9f
Removing intermediate container 739ab5566b9f
---> 9d2e5a894070
Step 3/4 : COPY ${JAR_FILE} test.jar
---> 2746354c80a5
Step 4/4 : ENTRYPOINT ["java", "-jar", "test.jar"]
---> Running in 9850a06d6686
Removing intermediate container 9850a06d6686
---> e5ec33eac8a9
Successfully built e5ec33eac8a9
Successfully tagged kazi-core:latest
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.test.Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
3条答案
按热度按时间wljmcqd81#
将
maven-assembly-plugin
添加到pom.xml例如:
hjqgdpho2#
使用spring Boot ,我们可以使用
spring-boot-maven-plugin
92dk7w1h3#
检查你的项目构建gradle文件,如果你有这样的东西:
只需将其删除并重新生成项目即可