任何在eclipse中使用M2E(maven-to-eclipse)插件的人都知道您在哪里运行构建的问题,然后在项目上更新maven只是让它重置JRE并抛出一堆项目错误! 我在使用Open Liberty与Java 9一起运行Java EE 8的帖子中注意到了这个问题
解决方案是确保编译器正在运行所需的正确版本,因此
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
要么 -
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
还有一点值得注意,如果您使用的是Java 9或更高版本,则版本号格式会有所不同。 因此,虽然Java 8的版本为1.8,但Java 9的版本为9
这意味着您需要将pom中的版本声明为
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
或在我的JavaEE8项目(https://github.com/farrelmr/javaee8/blob/master/pom.xml)中使用完整版本,则表示为–
<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>
<groupId>com.javabullets.javaee8</groupId>
<artifactId>javaee8</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>javaee8</finalName>
</build>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
</project>
这样可以防止日食问题
这篇文章可能看起来很明显–但值得一提的是,Java 9版本号的更改意味着您必须检查自己在maven中使用的版本号是否正确。
翻译自: https://www.javacodegeeks.com/2018/03/maven-eclipse-and-java-9.html