0

So I have my maven project configured to 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. If I manually correct that entry, everything is fine. But shouldn't Maven handle the complete classpath settings? The answer to this is probabbly quite simple, but I cant figure it out.

Thanks!

wron java version from the right jdk

EDIT The fix was to remove compilerVersion and edit the source and target tags:

<configuration>
    <source>9</source>
    <target>9</target>
</configuration>
Michael
  • 815
  • 1
  • 6
  • 23

2 Answers2

2

Step 1: Check PATH of MAVEN and JAVA

mvn -v

In the output check if "Java version" is pointing to 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)

  • Go to Preferences > Java > Installed JREs :: Check if Java 9 is available
  • If Java 9 is not available, then Click Add
  • Choose JRE Type Standard VM / JVM and click Next
  • JRE Home -- Java 9 Home path.
  • JRE name will get auto-filled and JRE system libraries will show jrt-fs.jar was loaded.
  • Hit Finish
  • Now you should see JVM 8 and 9 both showing up in the Installed JREs section
  • Hit Apply and Close

Step 3: Update your Maven Project for Changes to Take affect

  • Follow the tip given by Justin Albano and you are ready to work with your Maven Project using Java 9.
  • I am using the eclipse built-in maven. But it always sets down the version to SE1.5. If I set it to SE9 manually, some functions like call hierarchies and stuff like that wont work anymore, any ideas? – Michael Apr 21 '18 at 18:38
1

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. To bring the two back into sync, perform the following:

  1. Right click on the project
  2. Mouseover Maven
  3. Click Update Project...

You can also update the Maven configuration using Alt + F5. 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?.

Justin Albano
  • 3,809
  • 2
  • 24
  • 51
  • I of course tried that, but sometimes eclipse seems to do stuff and then its SE1.5 again. I have to manually overwrite the classpath over and over again. Funny thing is, if I set it to JDK9, the entry in the classpath overview from eclipse disappears and everyhing is fine :( – Michael Apr 21 '18 at 14:25
  • So I tried a few things at it turned out, that the update projects resets the project to se1.5. The error needs to be somewhere else :( – Michael Apr 21 '18 at 18:37