简体   繁体   English

Java版本-Maven-类路径?

[英]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! 谢谢!

右jdk的wron Java版本

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)

  • Go to Preferences > Java > Installed JREs :: Check if Java 9 is available 转到首选项> Java>已安装的JRE :: 检查Java 9是否可用
  • If Java 9 is not available, then Click Add 如果Java 9不可用,则单击“ 添加”。
  • Choose JRE Type Standard VM / JVM and click Next 选择“ JRE类型标准VM / JVM” ,然后单击“ 下一步”。
  • JRE Home -- Java 9 Home path. JRE Home -Java 9 Home路径
  • JRE name will get auto-filled and JRE system libraries will show jrt-fs.jar was loaded. JRE名称将自动填充, JRE系统库将显示jrt-fs.jar已加载。
  • Hit Finish 击中完成
  • Now you should see JVM 8 and 9 both showing up in the Installed JREs section 现在,您应该在“已安装的JRE”部分中看到同时显示了 JVM 8和9
  • Hit Apply and Close 点击应用并关闭

Step 3: Update your Maven Project for Changes to Take affect 步骤3:更新您的Maven项目以使更改生效

  • Follow the tip given by Justin Albano and you are ready to work with your Maven Project using Java 9. 遵循Justin Albano给出的技巧,您就可以使用Java 9处理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: 要使两者重新同步,请执行以下操作:

  1. Right click on the project 右键点击项目
  2. Mouseover Maven 鼠标悬停Maven
  3. Click 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM