[英]Java version - Maven - Classpath?
So I have my maven project configured to Java9 所以我将我的Maven项目配置为Java9
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.9</source>
<target>1.9</target>
<compilerVersion>1.9</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>
But if I check the project build path it still says JRE System Library [J2SE-1.5] in eclipse (instead of JavaSE-9), so it basically uses Java1.5 and gives me a lot of errors. 但是,如果我检查项目的构建路径,它仍然会在eclipse中(而不是JavaSE-9)说JRE系统库[J2SE-1.5],因此它基本上使用Java1.5,并且给我带来很多错误。 If I manually correct that entry, everything is fine.
如果我手动更正该条目,一切都很好。 But shouldn't Maven handle the complete classpath settings?
但是,Maven是否应该处理完整的类路径设置? The answer to this is probabbly quite simple, but I cant figure it out.
答案很可能很简单,但我无法弄清楚。
Thanks! 谢谢!
EDIT The fix was to remove compilerVersion and edit the source and target tags: 编辑解决方法是删除compileVersion并编辑源和目标标签:
<configuration>
<source>9</source>
<target>9</target>
</configuration>
Step 1: Check PATH of MAVEN and JAVA 步骤1:检查MAVEN和JAVA的路径
mvn -v
In the output check if "Java version" is pointing to 1.9 在输出中检查“ Java版本”是否指向1.9
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T13:28:13+05:30)
Maven home: /Maven/3.5.2
Java version: 9.0.4, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-9-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-119-generic", arch: "amd64", family: "unix"
Step 2: Check JDK 9 is configured in IDE (eclipse / sts) 步骤2:检查在IDE中配置了JDK 9(eclipse / sts)
Step 3: Update your Maven Project for Changes to Take affect 步骤3:更新您的Maven项目以使更改生效
Sometimes the Maven source version ( 1.9
is your particular case) and the Eclipse source version fall out of sync, especially if the source version in the pom.xml
file is changed after the project has been created in Eclipse. 有时,Maven源版本(您的特殊情况为
1.9
)与Eclipse源版本不同步,尤其是在Eclipse中创建项目后更改pom.xml
文件中的源版本时。 To bring the two back into sync, perform the following: 要使两者重新同步,请执行以下操作:
Maven
Maven
Update Project...
Update Project...
You can also update the Maven configuration using Alt + F5 . 您也可以使用Alt + F5更新Maven配置。 For more information, see What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?
有关更多信息,请参阅什么使Eclipse中导入的Maven项目默认情况下使用Java 1.5而不是Java 1.6,如何确保不这样做? .
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.