我有两个不同版本的spring config,分别对应两个不同的java版本,即java 8和java 11。
项目结构类似于:

pom.xml:
<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>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<toolchains>
<jdk>
<version>zulu-11</version>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>8</release>
</configuration>
</execution>
<execution>
<id>compile-java-11</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>11</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>但是在构建项目时,构建失败了,原因如下
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.981 s
[INFO] Finished at: 2021-10-01T21:56:03+05:30
[INFO] Final Memory: 23M/293M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.5:repackage (repackage) on project demo: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.5.5:repackage failed: Unab
le to find a single main class from the following candidates [com.example.demo.DemoApplication, META-INF.versions.11.com.example.demo.DemoApplication] -> [Help 1]
[ERROR]那么,有没有办法使用两个类而不会导致构建失败呢?
此外,我不能使用配置文件,也不能提到要在特定配置文件中使用的类。
发布于 2021-10-01 16:59:27
您可以在pom.xml中使用start-class属性来配置用于启动应用程序的类。
<properties>
<start-class>com.example.demo.DemoApplication</start-class>
</properties>当您使用java -jar在Java11上运行应用程序时,应该自动使用META-INF/versions/11中的DemoApplication变体。
https://stackoverflow.com/questions/69409408
复制相似问题