Java Platform extension from Oracle brings full featured development support (edit-compile-debug & test cycle) to VS Code. It offers support for Maven and Gradle projects.
View | Command Palette | Preferences:Open User Settings (JSON) ...
jdk: Jdkhome setting to point to JDK which Language Server will run on and projects will be compiled with. More below in section Selecting the JDKpublic static void main(String[] args)
method in opened folder and start coding, compiling, debugging. Works on JDK 11 and newer.In the VS Code command palette :
Project Explorer provides an overview of logical project structure, groups sources together and greatly simplifies Java package structure exploration. Project Explorer is an addition to the classical workspace explorer. Use it to build, test, execute and operate your Maven and Gradle Java projects.
Language Server Java+ ... launch configuration supports debugging and running Java applications using JDK11 or newer.
Run main | Debug main
code lense is selected in the code.Default launch configurations provided by Language Server can modified in launch.json
file.
Program arguments, VM options, evironment variables,... can be set in Run Configuration panel a part of Explorer. The panel is sufficient for all typical use-cases Java programmer faces. Only advanced, expert scenarios may require touching of launch.json
(which still takes precedence).
If the system does not detect any JDK, the extension will offer a downloader and setup prompt to help you set up a JDK. This setup provides options for Oracle JDK, OpenJDK, and allows you to choose from any installed JDK on your system.
Alternatively, you can manually specify the path to JDK binaries by utilizing the JDK downloader.
You can also access the JDK downloader through the "Download, install, and Use JDK" option in the command palette.
Class level refactorings as well as variable refactorings are supported in VSCode via Oracle Java Platform extension. See following screenshots:
Some refactorings are two steps with like Generate Override method ... where method to be overriden is selected in 2nd step:
Change method parameters refactoring is provided using dedicated form allowing to change, add, move, remove method parameters.
Move members refactoring provides dedicated form as well.
Easily update default formatter preferences by adjusting a simple configuration option to tailor settings according to specific needs.
Go to VSCode View | Command Palette | Preferences:Open User Settings | Extensions | Java
and set Jdk › Format: Settings Path:
option to the formatter preferences file.
Please refer to Java formatting preferences wiki for more info.
Easily update default hint preferences by adjusting a simple configuration option to tailor hint preferences to specific needs.
Go to VSCode View | Command Palette | Preferences:Open User Settings | Extensions | Java
and set Jdk › Hints: Preferences:
option to the xml hint preferences file.
Out of the box support for organizing imports in Java sources is available. It removes unused imports, groups imports by packages and updates your imports whenever a file is saved. In addition to the defaults, there is a rich set of configuration options.
Go to VSCode View | Command Palette | Preferences:Open User Settings | Extensions | Java
and search for Jdk to set Jdk > Java > Imports:
options:
Count For Using Star Import
- Class count to use a star-import, 999 is the default valueCount For Using Static Star Import
- Members count to use a static star-import, 999 is the default valueGroups
- Groups of import statements (specified by their package prefixes) and their sorting order. Import statements within a group are ordered alphabeticallyAnd View | Command Palette | Preferences:Open User Settings | Extensions > Java > On Save: Organize Imports
- Enable organize imports action on a document save
When adding JavaDoc to code Oracle Java Platform extension assists by suggesting to insert preformatted and prepopulated JavaDoc comment. Type /**
above method signature and IDE offers to complete the JavaDoc. The action creates JavaDoc comment with all arguments prepared.
Oracle Java Platform extension provides Test Explorer view which allows to run all tests in a project, examine the results, go to source code and run particular test.
The user projects are built, run and debugged using the same JDK which runs the Oracle Java Platform extension. The JDK is being searched in following locations:
jdk.jdkhome
setting (workspace then user settings)java.home
setting (workspace then user settings)JDK_HOME
environment variableJAVA_HOME
environment variableAs soon as one of the settings is changed, the Language Server is restarted.
This setup makes it easier to experiment with early access JDK builds. Follow these steps to enable the use of an early access JDK:
Step-1: Navigate to View | Command Palette | Preferences:Open User Settings | Jdk > Advanced > Disable: Nbjavac
and enable the checkbox.
Step-2: Set the JDK in View | Command Palette | Preferences:Open User Settings (JSON) ...
by updating the jdk.jdkhome setting to point to the early access JDK path.
If your extension is not starting and throwing some error like no JDK found even if you have a working JDK installed in your machine, then you can try deleting cache for the workspace using View | Command Palette | Delete oracle java extension cache for this workspace
.
The extension will analyze the content of the opened workspace, and relevant other files. If the workspace contains a lot of data, this may take a long time. It is therefore recommended to avoid adding unnecessarily big folders in a workspace. Specifically, it is not recommended to open user's home directory as a part of the workspace.
This project welcomes contributions from the community. Before submitting a pull request, please review our contribution guide
Please consult the security guide for our responsible security vulnerability disclosure process
Copyright (c) 2024 Oracle and/or its affiliates.
Oracle Java Platform Extension for Visual Studio Code is licensed under Apache 2.0 License. The THIRD_PARTY_LICENSES file contains third party notices and licenses.