【发布时间】:2016-06-16 04:52:30
【问题描述】:
将现有的 Maven 项目导入 Eclipse 时,从哪里驱动 JDK/JRE?例如,如下所示,在导入时,它被设置为 J2SE 1.4,但我希望它是 JDK 1.8。
如何在 Maven pom 中设置它,以便当其他开发人员获取项目时,导入时 Eclipse 将指向 JDK 1.8 而不是 1.4?
【问题讨论】:
将现有的 Maven 项目导入 Eclipse 时,从哪里驱动 JDK/JRE?例如,如下所示,在导入时,它被设置为 J2SE 1.4,但我希望它是 JDK 1.8。
如何在 Maven pom 中设置它,以便当其他开发人员获取项目时,导入时 Eclipse 将指向 JDK 1.8 而不是 1.4?
【问题讨论】:
我的建议是从 maven-compiler-plugin 插件的配置中指定 Java 的版本。请检查以下骨架。
<?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">
...
<properties>
...
<java.version>1.8</java.version>
...
</properties>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<verbose>true</verbose>
<debug>${debug}</debug>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
...
</plugins>
...
<resources>
...
</resources>
...
</build>
...
</project>
【讨论】: