Using VS Code with Java and Maven projects

Marc Englund
Marc Englund
On Dec 17, 2019 8:45:00 PM

Java is one of many languages supported by Visual Studio Code (VS Code). Like most things in VS Code, Java support is extension based. You may need several extensions, depending on the project type and stack you are working with. You can find more detail in Java in Visual Studio Code in the official VS Code documentation.

Fortunately, getting started is simple and you’ll probably already be familiar with most of the things.

1. Install the “Java Extension Pack”

This installs the most essential extensions for Java support. In many cases, it’s all you need. You can install the pack manually, or in response to the automatic prompt that displays when you first open a Java file.

VS Code open to the extensions tab

2. Open your project

Download a starter project from (or use an existing project), extract it into a folder, and then use Open Folder in VS Code to open the project. VS Code automatically recognizes that it is a Maven-based Java project and opens the Java Overview.

A folder containing a Maven project opened in VS Code

3. Build and run

Your project is now ready to run (and develop). You can use the Maven Projects panel to run a goal, or you can open a terminal (select Terminal>New Terminal) and run commands in your project folder.

Maven projects opened in the VS Code side menu. The "spring-boot:run" target is selected and output is printed to the console.

4. Develop

You may find that VS Code works similarly to what you are already used to. For instance, you can hover over a type to see more information; use CTRL/CMD+hover for more, and CTRL/CMD+click to navigate to the type.

An editor window showing a Java file. The mouse cursor is over a Notification class

5. Debug

Use F5 (or select Debug >Start Debugging) to start debugging. The first time you do this, VS Code automatically generates a launch configuration for you, and you have to select Start Debugging again to actually start the process. Once your application has started, you will find the usual debugging tools in the Debug view; for example, clicking to the left of the row number adds a breakpoint and so on.

A Java file with a breakpoint stopped at a return statement. VS Code shows controls for resuming

6. Next steps

Visual Studio Code is an advanced IDE with many convenient tricks up its sleeve. Take a look at the official documentation, and in particular the Writing Java with VS Code section that includes information about editing, running, debugging, and so on. There is also a section on Maven support in VS Code.

Happy coding!

Marc Englund
Marc Englund
Marc is a a long time Vaadineer, carrying a Design Strategist card in his left jeans pocket. Lately he has mostly been thinking about the new #FFS, and other ways to make the developers’ day more enjoyable.
Other posts by Marc Englund