Vscode-java: jdk8 not found errors, even though maven install works

Created on 28 Nov 2018  路  9Comments  路  Source: redhat-developer/vscode-java

_From @vishalpmittal on November 28, 2018 1:26_

Code just refuses to identify jdk 8. But if I right click maven project > myproject and click install, the maven project installs fine.

I keep seeing 1.8 error in problems tab:
"Lambda expressions are allowed only at source level 1.8 or above [1610613381] (line, column)"

User settings.json
"java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home",

Code : Version 1.29.1 (1.29.1)
Java Extension Pack 0.4.0
Mac OS High Sierra : Version 10.13.6

Already tried:

  • Cleaning up the workspace,
  • reinstalling java extension pack,
  • restart/reload code.
  • importing the same project in eclipse and building with 1.8 works fine.

_Copied from original issue: Microsoft/vscode-java-pack#68_

not-a-bug

Most helpful comment

So java.version is not a standard maven property. As @scarlet-begonias commented, it needs to be explicitly used in the maven-compiler-plugin configuration.

If you want to keep a lower verbosity, you need to use the standard properties. Either replace the <java.version> property with

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

or, if you want to keep the version in one place, simply add:

<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

Then make sure you run the update the project configuration command, if it's no automatic.

All 9 comments

I think this is not the first time we see issues about detects JDK on macOS

I searched and tried every possible workaround by now.
Is there a latest fix you know of ?

@vishalpmittal Duplicated with https://github.com/redhat-developer/vscode-java/issues/328.
Looks like you're running a maven project, and maven will use JDK 1.5 to compile your code by default. You need specify the source target to 1.8 in pom.xml.

@testforstephen
I have following already in my pom.xml. Is that the same ?

<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties>

@vishalpmittal , I have something like this in my pom.xml, maybe it will work for you?

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerVersion>${java.version}</compilerVersion>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
           </plugin>
        </plugins>
    </build>

@vishalpmittal can you please share your pom.xml?

Sure, PFA. I have renamed it to pom.txt.
pom.txt

You can also see it on github at:
https://github.com/vishalpmittal/practice-fun/blob/master/funNLearn/pom.xml

So java.version is not a standard maven property. As @scarlet-begonias commented, it needs to be explicitly used in the maven-compiler-plugin configuration.

If you want to keep a lower verbosity, you need to use the standard properties. Either replace the <java.version> property with

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

or, if you want to keep the version in one place, simply add:

<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

Then make sure you run the update the project configuration command, if it's no automatic.

Hey thanks for the help. no errors now.
didn't know i had to explicitly update that in maven.
I guess the reason is eclipse probably did it for me in past. But this is a better approach.

Was this page helpful?
0 / 5 - 0 ratings