DEV Community

Cover image for VSCode Java Extension Pack Auto Config
Shinji Kashihara
Shinji Kashihara

Posted on • Edited on

VSCode Java Extension Pack Auto Config

@openvsx tweet

Tired of manually installing and configuring JDKs for your Java projects? Try the Java Extension Pack JDK Auto extension by @willbrains and enjoy auto-download, auto-update and auto-configuration of JDKs! #OpenVSX #Java #vscode

 

Unlock the exhilarating world of Java development with the Java Extension Pack Auto Config! This powerful VSCode extension takes the hassle out of setting up and configuring your Java environment. Say goodbye to manual JDK installations and JAVA_HOME tinkering. With this pack, you can dive straight into coding without any configuration headaches. Get ready to unleash your Java coding skills with the Extension. It's time to embark on an exciting coding journey without the hassle of setup and configuration. Happy coding!

 

Java Extension Pack Auto Config
https://github.com/cypher256/java-extension-pack#readme
If you are searching from an extension on VSCode, search for "jdk auto". All of the following are quoted from the Marketplace description.


 

The extension greatly reduces the installation, configuration effort, and JDK configuration errors for general Java developers. There is no need to manually install the JDK or set the JAVA_HOME environment variables. It also comes pre-included with extensions that most Java developers need, such as Maven, Gradle, Spring, Lombok, and Tomcat start/stop, so you can start developing right out of the box with zero configuration.



Features

JDK Auto-configuration

The JDKs are auto-configured for the current environment on VSCode startup as follows. You can check the detected JDK in User settings.json described later or Output (Ctrl + Shift + U) ≫ Dropdown: JDK Auto. If there are multiple JDKs of the same version, the latest minor version among them is used. If you manually install or update the JDK and want to force update the configuration of VSCode, restart VSCode or execute >Developer: Reload Window from the command palette (F1 or Ctrl/Cmd + Shift + P). These are applied as user (VSCode global) settings. You can manually change user settings, but if you want to customize your settings even further, consider using workspace settings or profiles.

  1. Auto-fix invalid JDK configuration path (e.g. /jdk17/bin/java -> /jdk17)
  2. Auto-remove configuration entries when JDK uninstalled or version path changed
  3. Auto-scan from OS-specific location, SDKMAN, jEnv, jabba, ASDF, Gradle, Scoop, IntelliJ etc...
  4. Auto-detect environment variables JAVA_HOME, JDK_HOME and PATH
  5. Auto-download Adoptium LTS JDKs and available latest non-LTS JDK if not installed
  6. Auto-update auto-downloaded JDKs to the latest version
Configuration Name Configured Value (Priority)
(*1) java.jdt.ls.java.home
(Issues)
Latest LTS (*2)
(Setting > JDK_HOME > JAVA_HOME > PATH)
(*1) spring-boot.ls.java.home
(Issues)
Latest LTS (*2)
(Setting > JAVA_HOME > PATH)
(*1) rsp-ui.rsp.java.home
(Issues)
Latest LTS (*2)
(Setting > JDK_HOME > JAVA_HOME> Windows Registry > PATH)
java.home Delete due to deprecated entry
java.configuration.runtimes
(Issues)
Set all major JDKs scanned, detected, and downloaded
(Setting > JAVA_HOME)
java.import.gradle.java.home
(Issues)
Set default if unset
(Setting > java.jdt.ls.java.home)
maven.terminal.customEnv
(Issues)
Set default if JAVA_HOME environment variable unset
(Setting > JAVA_HOME)

(*1) The language server runtime used by VSCode extensions. Not for building and running projects.

(*2) Set latest LTS if unset, Fix if unsupported older version.



Auto-download Support

Up to 4 LTSs and the latest available non-LTS will be auto-downloaded if not installed. Unused old non-LTS that were previously auto-downloaded can safely be removed manually from the directory. Auto-download is supported on the following platforms:

  • Windows x64
  • macos x64, aarch64
  • Linux x64, aarch64

The downloaded JDKs are stored in the following JDK Auto extension global storage directory.

OS JDK Auto Extension global storage directory
Windows %APPDATA%\Code\User\globalStorage\pleiades.java-extension-pack-jdk\
macos $HOME/Library/Application Support/Code/User/globalStorage/pleiades.java-extension-pack-jdk/
Linux $HOME/.config/Code/User/globalStorage/pleiades.java-extension-pack-jdk/

e.g. Auto-configured User settings.json

Command Palette >Preferences: Open User Settings (JSON)



// JDT Language Server
"java.jdt.ls.java.home": "c:\\Program Files\\java\\jdk-17.0.6",
// ST4 Language Server
"spring-boot.ls.java.home": "c:\\Program Files\\java\\jdk-17.0.6",
// Runtime Server Protocol Server (Not AP server VM)
"rsp-ui.rsp.java.home": "c:\\Program Files\\java\\jdk-17.0.6",


Enter fullscreen mode Exit fullscreen mode


// Project Runtimes
"java.configuration.runtimes": [
  {
    "name": "JavaSE-1.8", // Adoptium (Auto-download)
    "path": "c:\\Users\\<UserName>\\AppData\\Roaming\\Code\\User\\globalStorage\\pleiades.java-extension-pack-jdk\\8"
  },
  {
    "name": "JavaSE-11", // Corretto (Auto-scan)
    "path": "c:\\Program Files\\Amazon Corretto\\jdk11.0.18_10"
  },
  {
    "name": "JavaSE-17", // Oracle (Auto-scan)
    "path": "c:\\Program Files\\java\\jdk-17.0.6",
    "default": true // for No build tools
  },
  {
    "name": "JavaSE-18", // JAVA_HOME (Auto-detect)
    "path": "d:\\jdk\\18"
  },
  {
    "name": "JavaSE-19", // Adoptium (Auto-scan)
    "path": "c:\\Program Files\\Eclipse Adoptium\\jdk-19.0.2.7-hotspot"
  }
],
// Gradle Daemon
"java.import.gradle.java.home": "c:\\Program Files\\java\\jdk-17.0.6",
// Maven Environment Variables
"maven.terminal.customEnv": [
  {
    "environmentVariable": "JAVA_HOME",
    "value": "c:\\Program Files\\java\\jdk-17.0.6"
  }
],


Enter fullscreen mode Exit fullscreen mode

 

 

Terminal Auto-configuration

Terminal profiles are defined based on configured runtimes, so you can easily open a terminal by selecting the Java version from command >Terminal: Create New Terminal (With Profile) or Terminal (Ctrl/Cmd + ) ≫ Profiles dropdown. The configured environment variables have no effect outside the terminal, so the system and OS user environment remain clean. TheJAVA_HOMEandPATH` in the auto-configured terminal configuration will always be overridden from the configured runtimes, so if you want to customize it, copy the terminal configuration entry and create a new one.
Switch Java Version

Configuration Name Configured Value (Original Default)
terminal.integrated.env.*
(Issues)
Set default if JAVA_HOME environment variable unset
(Setting > JAVA_HOME)
terminal.integrated.defaultProfile.windows
(Issues)
Set "Command Prompt" if unset on Windows
("PowerShell")
terminal.integrated.profiles.*
(Issues)
Set configured runtimes to terminal
(None)

A non-existent rcfile is specified so that JAVA_HOME and PATH are not overwritten at shell startup. If necessary, manually create the following rcfile.

OS Default Shell rcfile Location
Windows cmd -
macOS zsh ~/.zsh_jdkauto/.zshrc
Linux or WSL bash ~/.bashrc_jdkauto

 

 

Auto-default Settings

If the user settings is not set, it will auto-set the JDK Auto default value. Note that a debug run is required to enable Hot Code Replace (Hot Deploy).

Extension Name Configuration Name Original Default JDK Auto Default
Debugger for Java java.debug.settings.hotCodeReplace manual auto
Language support for Java java.sources.organizeImports.staticStarThreshold 99 1
VSCode editor.codeActionsOnSave {} See below
VSCode editor.minimap.enabled true false
VSCode editor.rulers [] See below
VSCode editor.unicodeHighlight.includeComments inUntrustedWorkspace true
VSCode workbench.colorCustomizations {} See below
VSCode workbench.tree.indent 8 20
VSCode (Windows) files.eol auto \n
VSCode (Windows) [bat] : files.eol files.eol \r\n
Code Spell Checker cSpell.diagnosticLevel Information Hint
Trailing Spaces trailing-spaces.includeEmptyLines true false

Default Settings

 

 

Language Pack Auto-installation

The language pack corresponding to the OS locale is installed at the first startup.

  • cs, de, es, fr, it, ja, ko, pl, ru, tr, zh-hans or zh-hant

 

 

Included Extension Features

Extension Pack for Java

Since many projects are nowadays using different Java versions in development, it is recommended to specify the Java version for each project instead of the JAVA_HOME environment variable so as not to affect the OS and OS user environment. To see which JDKs are used for your projects in multi-root workspaces, you can trigger the command Java: Configure Java Runtime in Command Palette. The Configure Runtime for Projects view is a feature of the Extension Pack for Java (Microsoft).
Configure Java Runtime

Change JDK for Gradle and Maven projects

If you want to change the JDK version for your Gradle or Maven projects, you need to update it in your build scripts (build.gradle or pom.xml). You can click ⓘ to see how to make such changes. Click 🖊 will navigate to the build script file of the project. Maven/Gradle version is recommended to be set per project in gradle-wrapper.properties/maven-wrapper.properties using wrapper gradlew/mvnw. For Spring Boot Gradle/Maven projects and general Gradle projects, these wrappers are included by default, so you don't need to install Gradle/Maven or set its environment variables.

Change JDK for unmanaged folders

To change the JDK for unmanaged folders (with out any build tools), you can click the 🖊 button. It will list all the JDKs and you can select one for your unmanaged folders. This changes the "default": true for java.configuration.runtimes. Currently, it is not possible to use different Java versions in multiple unmanaged folders within the same workspace.



Spring Boot Extension Pack

Set the JDK version when creating a Spring Boot project or in build.gradle/pom.xml.

![Spring Boot Dashboard](https://raw.githubusercontent.com/cypher256/java-extension-pack/main/image/spring.jpg)

Community Server Connectors

The JDK used to run the server for Servlet and Jakarta EE applications can be specified from the context menu ≫ Edit Servervm.install.path. The actual configuration files is in .rsp/redhat-community-server-connector/servers in the user home.

![Servers View](https://raw.githubusercontent.com/cypher256/java-extension-pack/main/image/servers.jpg)

 

 

Included Extensions

The Extension Pack for Java is required. Other extensions can be disabled per workspace or uninstalled according to your preference. If you want to set up extensions and configurations by development language, consider Profile. (*) indicates that it will be installed if available in that environment at first startup.

  • Extension Pack for Java (Microsoft: MIT) / VSCode Document Popular extensions for Java development that provides Java IntelliSense, debugging, testing, Maven/Gradle support, project management and more.
  • Spring Boot Extension Pack (VMWare: EPL) / VSCode Document A collection of extensions for developing Spring Boot applications.
  • Gradle for Java (Microsoft: MIT) / VSCode Document Manage Gradle Projects, run Gradle tasks and provide better Gradle file authoring experience in VS Code.
  • Community Server Connectors (Red Hat: EPL) / VSCode Document This VSCode Extension provides a Runtime Server Protocol based server connector, which can start, stop, publish to, and otherwise control Community runtimes and servers like Apache Felix, Karaf, and Tomcat.
  • Coverage Gutters (ryanluker: MIT) Display test coverage generated by lcov or xml - works with many languages.
  • Prettier - Code formatter (Prettier: MIT) Code formatter using prettier.
  • Code Spell Checker (Street Side Software: GPL) Spelling checker for source code.
  • Trailing Spaces (Shardul Mahadik: MIT) Highlight trailing spaces and delete them in a flash!
  • Indent-Rainbow (oderwat: MIT) Makes indentation easier to read.
  • Rainbow CSV (mechatroner: MIT) Highlight CSV and TSV files, Run SQL-like queries.
  • (*) GlassIt-VSC (hikarin522: MIT) VS Code Extension to set window to transparent on Windows and Linux platforms.
  • (*) Comment Translate (intellsmi: MIT) This plugin uses the Google Translate API to translate comments for the VSCode programming language.
  • (*) Language Pack (Microsoft: MIT) / VSCode Document A language pack that matches the OS Locale.

 

 

Recommended Extensions

The following are not included but are very useful extensions. Try to install it if necessary.

  • Error Lens (Alexander: Free) Improve highlighting of errors, warnings and other language diagnostics.
  • SonarLint (SonarSource: GPL) / VSCode Document SonarLint is an IDE extension that helps you detect and fix quality issues as you write code in C, C++, Java, JavaScript, PHP, Python, HTML and TypeScript.
  • GitHub Copilot (GitHub: Subscription) / VSCode Document Your AI pair programmer.
  • ChatGPT - Genie AI (Genie AI: Subscription) Your best AI pair programmer. Save conversations and continue any time. A Visual Studio Code - ChatGPT Integration. Supports GPT-4, GPT3.5, GPT3 and Codex models. Create new files, view diffs with one click; your copilot to learn code, add tests, find bugs and more.

Top comments (0)