Maven for Java, by Microsoft (overview - install )

Maven is the most widely used project build and dependency management tool in the Java ecosystem. So, this extension finally gets you to a point where you can work on pretty much any Java project, of any kind, through Visual Studio Code.

You will be able to generate and bootstrap Maven projects through Maven archetypes (skeletons), and then manage dependencies and trigger Maven goals, and edit the pom.xml file with some smart code completion.

Maven commands

Let's take a look:

Open the command pallet again, and type Maven.

Select Generate from Maven Archetype.

Select maven-archetype-quickstart.

The extension will ask for a destination folder, where the project folder will be generated. It will bring you to the terminal where you will have to input parameters to the Maven command-line, but don't worry as it will be guided.

Once the project is created, right from the terminal, call code <folder name> .

Open the newly created folder on VS Code

Alright, you should have your Maven project now opened on VS Code. The very basic thing you can do is Run your code. You have two choices here:

Run with the Run hyperlink inside the App class next to the main method, as we learned earlier. Use Maven, of course.

If you use the Debugger for Java extension (Run | Debug) triggers, the extension will use the classpath generated by Maven, to ensure all dependencies are properly added to the classpath.

To run with Maven though, you can either use the Terminal as usual, or open the Command Pallet and type Maven Execute Commands.

Command Pallet showing Maven actions

It will ask you to select a project. Since you have only one, hit Enter on it. Next what you will see is a list of all the default core Maven goals. Hit package to generate the JAR file.

If you want to run custom goals, such as those inherited from Maven plugins, you can use the Maven view:

Execute goals from Maven plugins

Once you edit your pom.xml file to add dependencies, VS Code will automatically reload the classpath and you should be able to import classes and packages from your new dependencies. Clean and smooth.

Java Test Runner, by Microsoft (overview - install )

Final step is to enhance how you run, debug, and visualize the results of your unit tests. This extension adds hyperlinks to unit tests (supports JUnit and TestNG) that can be executed individually, and you can see reports right away inside Visual Studio Code, like in the example below.

Running unit tests in VS Code

This extension will also enable the Test Explorer view, so you can focus on the unit tests of your code, and write software in a more TDD style.

Text Explorer

This extension currently works only with Maven projects, so make sure you have the Maven for Java extension installed as well.