Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Maven for JavaNew to Visual Studio Code? Get it now.
Maven for Java

Maven for Java

Microsoft

microsoft.com
|
48,501,268 installs
| (17) | Free
Manage Maven projects, execute goals, generate project from archetype, improve user experience for Java developers.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Maven for Java

Marketplace Version Installs Rating Build status

Features

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.

  • Support to generate projects from Maven Archetype.
  • Support to generate effective POM.
  • Provide shortcuts to common goals, plugin goals and customized commands.
  • Preserve command history to fast re-run.

Requirements

  • Java
  • Maven / Maven Wrapper

For troubleshooting, please refer to the page HERE.

Basic Usage

Maven Explorer

The extension scans pom.xml in your workspace, and displays all Maven projects and their modules in the sidebar.

Screenshot

Run Plugin Goals

The extension parse effective-pom of Maven projects, and displays all plugins and plugin goals hierarchically.

Screenshot

POM File Editing

The extension provides Maven specific completion suggestions when editing POM files, including snippets and artifact hints.

Screenshot

Re-Run Historical Commands

It preserves history of goals for each project, so you can fast re-run previous long commands, e.g. mvn <goals> -Dparam1=value1 -Dparam2=value2 -Dparam3=value3 ... There are 2 entries for it:

  • Command Palette -> select Maven: History ... -> Select a project -> Select command from the history
  • Right-click on a project -> Click History ... -> Select command from the history

Screenshot

Archetype Related

Generate from Maven Archetype

The extension loads archetypes listed in local/remote catalog. After selection, the extension sends mvn archetype:generate -D... to terminal. There are 2 entries for it:

  • Command Palette -> select Maven: Generate from Maven Archetype
  • Right-click on a folder -> Click Generate from Maven Archetype

Screenshot

Update Maven Archetype Catalog

With following steps, you can update the local cache of Maven remote catalog. It takes some time to download meta data from Maven central repository.

Command Palette -> select Maven: Update Maven Archetype Catalog.

Additional Configurations

JAVA_HOME and Other Environment Variables

This extension executes Maven by opening a terminal session and then calling Maven in that session. Maven requires the JAVA_HOME environment variable to be set. Maven will also look for other variables such as MAVEN_OPTS. If you prefer not to set those variables permanently you can configure them, or any other environment variable, in settings:

{
    "maven.terminal.customEnv": [
        {
            "environmentVariable": "MAVEN_OPTS",               // variable name
            "value": "-Xms1024m -Xmx4096m"                     // value
        },
        {
            "environmentVariable": "JAVA_HOME",                // variable name
            "value": "C:\\Program Files\\Java\\jdk-9.0.4"      // value
        }
    ]
}

Using a different JDK for Maven than your system default

If mvn is picking up the wrong JDK (e.g. the system default JDK 17 is used even though your project targets JDK 1.8), set the JAVA_HOME entry in maven.terminal.customEnv to the JDK installation you want Maven to use. This setting is honored by every command this extension runs — both Maven commands launched in the integrated terminal and background commands such as effective-pom generation.

The setting is per-folder, so in a multi-root workspace you can configure a different JDK for each folder via the folder's .vscode/settings.json.

Already-open Maven terminals keep their environment from the moment they were created. After changing this setting, close any existing Maven terminal (or reload the window) so the next command picks up the new value.

Special Handling for JAVA_HOME

To run Maven with a specific JDK, set JAVA_HOME via maven.terminal.customEnv (see the section above). This value is applied to both terminal commands and background commands launched by this extension.

Default Options for Maven Command The usage of Maven executable is:

usage: mvn [options] [<goal(s)>] [<phase(s)>]