【发布时间】:2019-09-04 11:13:31
【问题描述】:
当我尝试在 Eclipse 中编译(运行 maven 安装)时,我收到了不兼容的错误。似乎出于某种原因,maven 使用旧的 jre/jdk 并且不使用路径环境。变量。即使当我运行 mvn -v 时,它也会输出 maven 使用正确的版本(在我的本地机器上)
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/databasePackage/implementations/DBConnection.java:[132,21] try-with-resources is not supported in -source 1.5
(use -source 7 or higher to enable try-with-resources)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/databasePackage/implementations/DBConnection.java:[223,50] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/DBConnection.java:[64,38] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/DBConnection.java:[80,21] try-with-resources is not supported in -source 1.5
(use -source 7 or higher to enable try-with-resources)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/databasePackage/implementations/ObjectComparators.java:[21,48] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/ObjectComparators.java:[21,48] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/DatabaseTable.java:[420,51] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[INFO] 7 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.142 s
[INFO] Finished at: 2019-04-14T09:44:36+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project PetClinic: Compilation failure: Compilation failure:
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/databasePackage/implementations/DBConnection.java:[132,21] try-with-resources is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable try-with-resources)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/databasePackage/implementations/DBConnection.java:[223,50] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/DBConnection.java:[64,38] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/DBConnection.java:[80,21] try-with-resources is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable try-with-resources)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/databasePackage/implementations/ObjectComparators.java:[21,48] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/ObjectComparators.java:[21,48] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /C:/Users/Barracuda/Desktop/Projects/Eclipse Projects/PetClinicWeb/src/main/java/com/model/adv/DatabaseTable.java:[420,51] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] -> [Help 1]
[ERROR]
我应该如何解决这个问题?我可以在不每次在 POM.xml 中指定要使用的版本的情况下做到这一点,而是告诉 maven 使用 Path env。变种。 ? 这是eclipse中指定的内容:
这是 JAVA_HOME 环境。变量。
这里 — mvn -v 和 java -version 的输出
这是我的 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.arslan</groupId>
<artifactId>PetClinic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Pet Clinic Web Application</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
即使从命令行运行 mvn install 也无济于事。
【问题讨论】: