Apache NetBeans Language Server Extension for VS Code
This is a technology preview of Apache NetBeans
based extension for VS Code. Use it to get all the goodies of NetBeans
via the VS Code user interface! Runs on JDK8[*] 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.
Set JDK in
VSCode | Preferences | Settings ... Netbeans: Jdkhome setting to point to JDK which Language Server will run on and projects will be compiled with. More below in section Selecting the JDK
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).
- Language Server opens the project, performs priming build and might ask for Resolving problems, usually related to opening
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.
- Java: New Project... allows creation of new Maven or Gradle project
- Java: New from Template... add various files to currently selected open project. Files are:
- Java - broad selection of various predefined Java classes
- Unit tests - JUnit and TestNB templates for test suites and test cases
- Other - various templates for JSON, YAML, properties, ... files
- Java: Compile Workspace - invoke Maven or Gradle build
- Debugger Java 8+... - start main class or test on JDK8+. More in Debugger section
- Progress shown for long running operations with cancel support for selected types
- Native Image Debugger is a new Run configuration added which allows Java style debugging of Ahead of Time compiled native-images, produced by GraalVM. It is experimental feature which works with GDB on Linux. GDB 7.11 or GDB 10.1+ is required due to known issue #26139 in GDB 8 and 9.
- It is also possible to attach to running native image process using Attach to Native Image launch configuation.
- Micronaut and Spring support especially for YAML configuration files with code completion and source code navigation to Java.
- Test Explorer for Java tests results visualization and execution including editor code Lenses.
- Maven and Gradle support including multi-project projects, subprojects opening and Gradle priming builds.
Debugger and Launch Configurations
Language Server Java 8+ ... launch configuration supports debugging and running Java applications using JDK8 or newer.
- The launch configuration (debugger) is invoked when
Run main | Debug main code lense is selected in the code.
- Or Java 8+... is selected in Run and Debug activity panel.
- Launch Java 8+ App - Debug or Run current Java project
- Launch Java: Continuous Mode - Runs Micronaut project and reloads it when source code has been changed.
- Attach to Port & Attach to Process - Attach debugger actions. Available when Java 8+ ... at the bottom of drop down list is selected.
- Select this configuration, then click the
- Select either from available process or enter the port to connect to JVM running with JDWP.
- Attach to Shared Memory is available on Windows in addtion to above mentioned Attach...
Default launch configurations provided by Language Server can modified in
launch.json file using intellisense for available options.
Class level refactorings as well as variable refactorings are supported in VSCode via Apache NetBeans extension. See following screenshots:
Introduce refactorings available via Show Code actions light bulb
Surroung with refactorings
Some refactorings are two steps with like Override method ... where method to be overriden is selected in 2nd step:
Some of supported refactorings:
- Convert to static import
- Pull member up & down
- Move class
- Extract interface/method
- Extract local variable
- Assign to variable
- Generate hashCode/equals
- Generate toString()
- Change method signature
- Surround With refactoring
- For cycle refactoring
- try-catch refactoring
- switch() statement
- while() cycle
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.
Native Image Debugger
NetBeans Language Server allows Java like debugging of native images produced by GraalVM EE 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. GraalVM Enterprise Edition is needed as it produces full debug information for native images, at this time.
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
Using Native Image Maven Plugin
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
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.
- netbeans.jdkhome - path to the JDK, see dedicated section below
- netbeans.verbose - enables verbose extension logging
- netbeans.conflict.check - avoid conflicts with other Java extensions, see below
Selecting the JDK
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
netbeans.jdkhome setting (workspace then user settings)
java.home setting (workspace then user settings)
JDK_HOME environment variable
JAVA_HOME environment variable
- current system path
As soon as one of the settings is changed, the Language Server is restarted.
Conflicts with other Java Extensions
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
Read building instructions to help Apache community to
improve the extension.