Here is a complete list of steps - you may not need steps 1-3 but am including them for completeness:-

  1. Download VS Code and Apache Maven and install both.
  2. Install the Visual Studio extension pack for Java - e.g. by pasting this URL into a web browser: vscode:extension/vscjava.vscode-java-pack and then clicking on the green Install button after it opens in VS Code.
  3. NOTE: See the comment from ADTC for an "Easier GUI version of step 3...(Skip step 4)." If necessary, the Maven quick start archetype could be used to generate a new Maven project in an appropriate local folder: mvn archetype:generate -DgroupId=com.companyname.appname -DartifactId=appname -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false. This will create an appname folder with Maven's Standard Directory Layout (i.e. src/main/java/com/companyname/appname and src/main/test/com/companyname/appname to begin with and a sample "Hello World!" Java file named appname.java and associated unit test named appnameTest.java).*
  4. Open the Maven project folder in VS Code via File menu -> Open Folder... and select the appname folder.
  5. Open the Command Palette (via the View menu or by right-clicking) and type in and select Tasks: Configure task then select Create tasks.json from template.
  6. Choose maven ("Executes common Maven commands"). This creates a tasks.json file with "verify" and "test" tasks. More can be added corresponding to other Maven Build Lifecycle phases. To specifically address your requirement for classes to be built without a JAR file, a "compile" task would need to be added as follows:
    {
        "label": "compile",
        "type": "shell",
        "command": "mvn -B compile",
        "group": "build"
    },
  1. Save the above changes and then open the Command Palette and select "Tasks: Run Build Task" then pick "compile" and then "Continue without scanning the task output". This invokes Maven, which creates a target folder at the same level as the src folder with the compiled class files in the target\classes folder.

Addendum: How to run/debug a class

Following a question in the comments, here are some steps for running/debugging:-

  1. Show the Debug view if it is not already shown (via View menu - Debug or CtrlShiftD).
  2. Click on the green arrow in the Debug view and select "Java".
  3. Assuming it hasn't already been created, a message "launch.json is needed to start the debugger. Do you want to create it now?" will appear - select "Yes" and then select "Java" again.
  4. Enter the fully qualified name of the main class (e.g. com.companyname.appname.App) in the value for "mainClass" and save the file.
  5. Click on the green arrow in the Debug view again.
Answer from Steve Chambers on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-build
Java build tools in VS Code
November 3, 2021 - The Maven for Java extension for Visual Studio Code provides fully integrated Maven support, allowing you to explore Maven projects, execute Maven commands, and perform the goals of build lifecycle and plugins.
Top answer
1 of 5
138

Here is a complete list of steps - you may not need steps 1-3 but am including them for completeness:-

  1. Download VS Code and Apache Maven and install both.
  2. Install the Visual Studio extension pack for Java - e.g. by pasting this URL into a web browser: vscode:extension/vscjava.vscode-java-pack and then clicking on the green Install button after it opens in VS Code.
  3. NOTE: See the comment from ADTC for an "Easier GUI version of step 3...(Skip step 4)." If necessary, the Maven quick start archetype could be used to generate a new Maven project in an appropriate local folder: mvn archetype:generate -DgroupId=com.companyname.appname -DartifactId=appname -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false. This will create an appname folder with Maven's Standard Directory Layout (i.e. src/main/java/com/companyname/appname and src/main/test/com/companyname/appname to begin with and a sample "Hello World!" Java file named appname.java and associated unit test named appnameTest.java).*
  4. Open the Maven project folder in VS Code via File menu -> Open Folder... and select the appname folder.
  5. Open the Command Palette (via the View menu or by right-clicking) and type in and select Tasks: Configure task then select Create tasks.json from template.
  6. Choose maven ("Executes common Maven commands"). This creates a tasks.json file with "verify" and "test" tasks. More can be added corresponding to other Maven Build Lifecycle phases. To specifically address your requirement for classes to be built without a JAR file, a "compile" task would need to be added as follows:
    {
        "label": "compile",
        "type": "shell",
        "command": "mvn -B compile",
        "group": "build"
    },
  1. Save the above changes and then open the Command Palette and select "Tasks: Run Build Task" then pick "compile" and then "Continue without scanning the task output". This invokes Maven, which creates a target folder at the same level as the src folder with the compiled class files in the target\classes folder.

Addendum: How to run/debug a class

Following a question in the comments, here are some steps for running/debugging:-

  1. Show the Debug view if it is not already shown (via View menu - Debug or CtrlShiftD).
  2. Click on the green arrow in the Debug view and select "Java".
  3. Assuming it hasn't already been created, a message "launch.json is needed to start the debugger. Do you want to create it now?" will appear - select "Yes" and then select "Java" again.
  4. Enter the fully qualified name of the main class (e.g. com.companyname.appname.App) in the value for "mainClass" and save the file.
  5. Click on the green arrow in the Debug view again.
2 of 5
12

An alternative way is to install the Maven for Java plugin and create a maven project within Visual Studio. The steps are described in the official documentation:

  1. From the Command Palette (Crtl+Shift+P), select Maven: Generate from Maven Archetype and follow the instructions, or
  2. Right-click on a folder and select Generate from Maven Archetype.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Maven for Java - Visual Studio Marketplace
Extension for Visual Studio Code - Manage Maven projects, execute goals, generate project from archetype, improve user experience for Java developers.
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-project
Managing Java Projects in VS Code
November 3, 2021 - Lightweight Mode, Maven Support, Java Package and Dependency Management in Visual Studio Code
🌐
Vaadin
vaadin.com › blog › vs-code-for-java-and-maven-projects
How to use Visual Studio Code with Java and Maven projects | Vaadin
March 28, 2025 - Download a starter project from start.vaadin.com (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.
🌐
Gitbooks
gorkem1.gitbooks.io › visual-studio-code-for-java › content › chapter-1 › Maven-Create.html
Creating a Java Project Maven · Visual Studio Code for Java
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false ... At this point your project can be edited with VS Code and you should be getting Java language features such as code assist.
🌐
Reddit
reddit.com › r/java › will i have an easier time using maven + vscode instead of gradle + vscode?
Will I have an easier time using maven + vscode instead of gradle + vscode? : r/java
February 27, 2022 - VSCode support for Java is done by Red-Hat and Microsoft, and it is basically headless Eclipse. ... It just uses Eclipse's compiler for part of its compilation and as the language server. A lot of the other parts (e.g. debugger, test runner, maven integration, ...) are not based on Eclipse.
🌐
Medium
medium.com › @xjfreddie › creating-a-maven-project-in-vscode-1f7de148ee55
Creating a maven project in VSCODE | by F.Jensen | Medium
December 27, 2022 - Alternatively, you can use the Maven extension for Visual Studio Code to run Maven goals. To do this, right-click on the pom.xml file and select Run Maven Goal. Note: Make sure that you have the Java Development Kit (JDK) installed and configured properly on your system.
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › java
Java in Visual Studio Code
November 3, 2021 - When working with "Java projects" in VS Code, you must have the necessary extensions installed to work with those project files. For example, Maven, Eclipse, and Gradle Java projects are supported through Language Support for Java™ by Red Hat, by utilizing M2Eclipse, which provides Maven support, and Buildship, which provides Gradle support through the Eclipse JDT Language Server.
🌐
Sungsoo
sungsoo.github.io › 2022 › 05 › 30 › maven-vs-code.html
Using Visual Studio Code (VSCode) for Java Maven Project
Flow to install the Java and Maven extension. Some setup tricks to get starteday. How to create Maven project using vscode 2021 on windows.
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-tutorial
Getting Started with Java in VS Code
November 3, 2021 - Java Project Management shows you how to use a project view and work with Maven
🌐
Microsoft
devblogs.microsoft.com › dev blogs › microsoft for java developers › java on visual studio code update – february 2024
Java on Visual Studio Code Update - February 2024 - Microsoft for Java Developers
March 5, 2024 - Developer just needs to right click and bring up the File context menu in the File Explorer, find Maven and click on “New Maven Module“. The instructions then will provide simplified steps to add a module to the existing project.
🌐
Java Guides
javaguides.net › 2024 › 11 › how-to-create-maven-project-in-vs-code.html
How to Create a Maven Project in Visual Studio Code (VS Code) IDE
November 30, 2024 - Generate Maven Project Type and select Maven: Create Maven Project. ... Choose an archetype to define your project structure. For a basic Java application, select maven-archetype-quickstart.
🌐
GitHub
github.com › microsoft › vscode-maven
GitHub - microsoft/vscode-maven: VSCode extension "Maven for Java"
Maven extension for VS Code. It provides a project explorer and shortcuts to execute Maven commands, improving user experience for Java developers who use Maven.
Starred by 191 users
Forked by 94 users
Languages   TypeScript 75.2% | JavaScript 15.3% | Java 9.5%
🌐
Broadcom
knowledge.broadcom.com › external › article › 256447 › how-to-configure-maven-plugin-nolio-lcm.html
How to configure Maven Plugin - Nolio LCM in VS code
October 17, 2023 - The Maven Plugin - Nolio LCM can be configured with Microsoft Visual Studio Code (a.k.a. vscode). Follow the steps below for configuration. 1: Download the VS code for your respective environment and install the same · 2: With successful installation of VS code, launch VS code application ...
🌐
Codename One
codenameone.com › blog › better-vscode-support-for-maven-projects.html
Better VSCode Support for Maven Projects - Codename One
June 9, 2022 - You may be prompted to install the Java Extension Pack in one of the notices in the lower-right corner. If so, you should follow these prompts to install that extension. Unfortunately VSCode “Run” button doesn’t work to run the project in the simulator. We’re working on that. To run the project in the Codename One simulator, you’ll need to use the “Run in Simulator” command which is available in the Maven favorites menu.