Languages

Is there way to configure Java 19 (or upper) in VS Code?

5 points
Asked by:
kaya31
526

As I noticed, VS Code supports currently Java 8, 11 and 19.

Is there way to configure Java 19 (or upper) in VS Code?

JDK installation in VS Code.
JDK installation in VS Code.
1 answer
7 points
Answered by:
kaya31
526

Prerequirements: installed Java 19 on your computer (read this article).

 

Under Windows:

  1. press Ctrl+Shift+P keys,
     
  2. find and select Preferences: Open User Settings (JSON) option,
     
  3. add "java.configuration.runtimes" configuration,
    e.g.:
    {
        // ...
        "java.configuration.runtimes": [
          {
            "name": "JavaSE-11",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-11.0.19.7-hotspot",
          },
          {
            "name": "JavaSE-17",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.8.101-hotspot",
          },
          {
            "name": "JavaSE-19",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-19.0.2.7-hotspot",
            "default": true
          }
        ],
        // ...
    }
    Note: you can use other JDK than Eclipse Adoptium.

 

Sometimes it may be needed to change Java version to 19 in pom.xml file when you use Maven project.
e.g.:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>my-project</artifactId>

    <name>My project</name>
    <description>My project description.</description>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <java.version>19</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>

        <!-- ... -->

    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

 

See also

  1. Java - download Adopt Open JDK for free - Java 8, 11, 16, 17, 19 or 20 
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join