I installed OpenJDK 18 in my Fedora 36 and installed "Extension Pack for Java" on my Visual Studio Code. In my machine, there have 3 versions of java:
But when I create a maven project and run it in VS Code, I found it used java 11. How can I configure VS code to let it run projects on Java 18?
CodePudding user response:
Use Ctrl Shift P to open the command palette, search for and select Java: Configure Java Runtime .
or click the three dots after the Java project and select Configure Java Runtime.
Select the version you want from the drop-down options.
CodePudding user response:
To config to the right JDK in VS Code. Open File -->Settings --> Java --> Configuration:Runtimes -->[Edit in Setting.json] add:
"java.configuration.runtimes": [
{
"name": "JavaSE-18",
"path": "/usr/lib/jvm/java-18-openjdk-18.0.1.1.2-1.rolling.fc36.x86_64",
"sources" : "/usr/lib/jvm/java-18-openjdk-18.0.1.1.2-1.rolling.fc36.x86_64/lib/src.zip",
"javadoc" : "/usr/share/javadoc/java-18-openjdk-18.0.1.1.2-1.rolling.fc36.x86_64/api",
"default": true
}
]
The path is the "$JAVA_HOME" if you run
$sudo alternatives --config java
and the result is
3 java-latest-openjdk.x86_64 (/usr/lib/jvm/java-18-openjdk-18.0.1.1.2-1.rolling.fc36.x86_64/bin/java)
so JAVA_HOME is /usr/lib/jvm/java-18-openjdk-18.0.1.1.2-1.rolling.fc36.x86_64
The source, if you install sudo dnf install java-latest-openjdk-src.x86_64
the source code will be $JAVA_HOME/lib/src.zip
To find the Javadoc if you install "java-latest-openjdk-javadoc.x86_64
",
you can use command rpm -pl java-latest-openjdk-javadoc.x86_64
to check the installation location.