This is Apache NetBeans Language Server extension for VS Code. Use it to get all the goodies of NetBeans via the VS Code user interface! Runs on JDK17 and all newer versions.
Apache NetBeans Language Server brings full featured Java development (edit-compile-debug & test cycle) for Maven and Gradle projects to VSCode. As well as other features.
Use command Java: JDK Configuration to set same JDK in Apache NetBeans Language Server and all other Java settings in VSCode like Integrated terminal JAVA_HOME
and PATH
, Maven Runtime and JDK for MS Java as well if installed:
netbeans.jdkhome
is also available in VSCode | Preferences | Settings ...
Netbeans: Jdkhome
. More below in section Selecting the JDKnetbeans.project.jdkhome
holds a path to a JDK that is used as a default platform for opened folder/workspace (e.g. Java project). To avoid possible issues with default platform changing (i.e. changes from JDK21 to JDK8), NBLS is restarted when netbeans.project.jdhome
changes.Use Java: New Project... " command to start creating new project, or
Open the folder with existing pom.xml for Maven or Gradle project files (build.gradle, gradle.properties).
Or simply create a new Java class file with public static void main(String[] args)
method in opened folder and start coding, compiling, debugging. Works on JDK 8 and newer.
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 using intellisense for available options.
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).
Class level refactorings as well as variable refactorings are supported in VSCode via Apache NetBeans extension. See following screenshots:
Some refactorings are two steps with like Override method ... where method to be overriden is selected in 2nd step:
Change method parameters refactoring is provided using dedidacated form allowing to change, add, move, remove method parameters.
Move members refactoring provides dedicated form as well.
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 Preferences | Settings
and search for NetBeans to set Netbeans > Java > Imports:
options:
Count For Using Star Import
- Class count to use a star-import, 999 means any numberCount For Using Static Star Import
- Members count to use a static star-import, 999 means any numberGroups
- Groups of import statements (specified by their package prefixes) and their sorting order. Import statements within a group are ordered alphabeticallyAnd Netbeans > Java > On Save: Organize Imports
- Enable organize imports action on a document save
When adding JavaDoc to code NetBeans 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.
Formatting source code is possible using the NetBeans code style. For using non default formatter options, simply export desired settings from NetBeans IDE into standard file and then set Netbeans > Format: Settings Path:
in VSCode Settings.
NetBeans Language Server provides Test Explorer view which allows to run all tests in a project, examine the results, go to source code and run particular test.
NetBeans Language Server allows Java like debugging of native images produced by GraalVM native-image tool. It is provided using GDB and via new Run configuration named Launch Native Image. This experimental feature works now only on Linux with certain version of GDB, see above.
In order to debug native image applications it is necessary to build such native image with debug information available. It can be done by providing following switches for native-image tool:
-g -O0
or-H:Debug=2 -H:Optimize=0
.It is possible to use Native-Image Maven Plugin to run native-image builds for Maven projects. In this case add following <buildArgs>
into plugin <configuration>
:
<buildArgs> <buildArg>-g</buildArg> <buildArg>-O0</buildArg> </buildArgs>
Setting project's Maven pom.xml to skip native-image build everytime when project is being built is a good practice.
When native image is built, including debug info then add Launch Native Image configuration to launch.json. Select it in Run & Debug activity window and press F5 to debug Java source code on native image.
Database Explorer allows to connect to databases using appropriate JDBC drivers. Make Default Connection sets selected Database connection as default for IDE. This connection is then used by all IDE editors for SQL Code completion, or Micronaut Data queries, e.g. findByPagesGreaterThan
Oracle Cloud Infrastructure Explorer supports viewing compartments and resources available on user OCI instance. It is defined by OCI config file which has to be downloaded according to OCI instructions and saved in <users_home>/.oci/config
It is possible to add JDBC connection to Oracle Autonomous DB running in OCI using Add DB Connection menu. It downloads DB Wallet automatically.
Cloud Assets panel shows Micronaut OCI Properties to be set. These are read from project artefacts currently provided in project pom.xml or build.gradle. When user OCI configuration file .oci/config
is present it allows to set various OCI assets (resources) needed for project runtime using user OCI tenancy.
It is also possible to generate suggested OCI Policies needed by project to run in OCI and copy & paste these policies into OCI Cloud Console.
The user projects are built, run and debugged using the same JDK which runs the Apache NetBeans Language Server. The JDK is being searched in following locations:
netbeans.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.
The extension will check if source level Java (defined in the project) is compatible with the one used by extension. It checks if the source level Java version is lower or equal to the Java version used by extension, and if this condition is not fulfilled, it will show warning message.
It will not perform the check if the RedHat extension is installed.
It is possible to run Apache NetBeans Language Server per workspace (VSCode window). This allows separation of Language Server for given project as Language Server JVM is not shared for more VSCode open workspaces (projects). It is possible to change this in Preferences | Settings | Netbeans: Userdir
. Set to local
to use dedicated Language Server per workspace or set to global
(this is default) to have one Language Server for all VSCode workspaces.
Apache NetBeans Language Server extension isn't the only Java supporting extension. To avoid duplicated code completion and other misleading clashes the extension disables certain functionality known to cause problems, this is done per Workspace.
This behavior can be disabled by setting netbeans.conflict.check
setting to false
.
Read building instructions to help Apache community to improve the extension.