刚接触Java和Docker,try 使用以下方法对this(我的第一个Spring Boot应用程序)进行dockered:
Dockerfile
FROM maven:3.8.4-jdk-11 AS build
COPY src /app/src
COPY pom.xml /app
WORKDIR /app
RUN mvn clean install -U
FROM openjdk:8-jre-alpine
COPY --from=build /app/target/mal-randomizer-0.0.1-SNAPSHOT.jar /app/app.jar
WORKDIR /app
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]
昨晚多次出现此错误:
20.09 [INFO] Compiling 8 source files with javac [debug release 21] to target/classes
20.18 [INFO] ------------------------------------------------------------------------
20.18 [INFO] BUILD FAILURE
20.18 [INFO] ------------------------------------------------------------------------
20.18 [INFO] Total time: 19.160 s
20.18 [INFO] Finished at: 2024-04-22T14:49:00Z
20.18 [INFO] ------------------------------------------------------------------------
20.18 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project mal-randomizer: Fatal error compiling: error: release version 21 not supported -> [Help 1]
20.18 [ERROR]
20.18 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
20.18 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
20.18 [ERROR]
20.18 [ERROR] For more information about the errors and possible solutions, please read the following articles:
20.18 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我try 了多种解决方案,例如:
- 重新定义我的
JAVA_HOME
个环境 - 改变了形象
- 更改了
pom.xml
Java版本、专家编译器目标和源 *
* 如果我将Java版本降级太多(低于Java 16),我的代码将无法运行,因为16中已经引入了记录.
我相信解决方案在于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>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.victorfernandesneto</groupId>
<artifactId>mal-randomizer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mal-randomizer</name>
<description>MyAnimeList's Unofficial List Randomizer</description>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>