Michael
Michael

Reputation: 815

Java version - Maven - Classpath?

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>

Upvotes: 0

Views: 560

Answers (2)

narayan-sambireddy
narayan-sambireddy

Reputation: 335

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.

Upvotes: 2

Justin Albano
Justin Albano

Reputation: 3939

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?.

Upvotes: 1

Related Questions