Tutorials  /  JavaScript

Efficient Working with Maven: 24 Commands and Options Overview

Ccentron Redaktion · May 2024 ·5 min read ·JavaScript, Tutorial

Introduction

Maven is one of the most popular tools for project and dependency management in Java applications. It provides a variety of commands and options that can assist you in your daily tasks. In this cheat sheet, we use a sample project to demonstrate some useful Maven commands. Originally written for OpenJDK 13.0.1 and Maven 3.6.3, these commands have been verified with OpenJDK 19.0.1 and Maven 3.8.7.

VM

Matching infrastructure at centron

Node applications need somewhere to run: ccloud³ VMs with full root access from €3.12 per month – or as a managed server if you would rather not run it yourself. Rent a cloud server →

Maven Commands

1. `mvn clean`

With this command, you can clean the Maven project by deleting the `target` directory:

Code
mvn clean

2. `mvn compiler:compile`

This command compiles the Java source classes of the Maven project:

Code
mvn compiler:compile

3. `mvn compiler:testCompile`

This command compiles the test classes of the Maven project:

Code
mvn compiler:testCompile

4. `mvn package`

This command builds the Maven project and packages it into a JAR, WAR, etc.:

Code
mvn package

5. `mvn install`

This command builds the Maven project and installs the project files (JAR, WAR, pom.xml, etc.) to the local repository:

Code
mvn install

6. `mvn deploy`

This command deploys the artifact to the remote repository. This requires proper configuration of the remote repository in the project's `code>pom.xml` file and providing authentication details in Maven's `settings.xml` file.

Code
mvn deploy

7. `mvn validate`

This command validates the Maven project to ensure that everything is correct and all the necessary information is available:

Code
mvn validate

8. `mvn dependency:tree`

Generates the dependency tree of the Maven project:

Code
mvn dependency:tree

9. `mvn dependency:analyze`

This command analyzes the Maven project to identify unused declared and used undeclared dependencies:

Code
mvn dependency:analyze

10. `mvn archetype:generate`

Generates skeleton Maven projects of different types, such as JAR, web application, Maven site, etc.:

<

Code
mvn archetype:generate

11. `mvn site:site`

Generates a site for the project:

Code
mvn site:site

12. `mvn test`

This command runs the test cases of the project:

Code
mvn test

13. `mvn compile<`

Compiles the source Java classes of the project:

Code
mvn compile

14. `mvn verify`

Builds the project, runs all the test cases, and checks the results of integration tests to ensure quality criteria are met:

Code
mvn verify

15. `mvn -help`

Displays the Maven command line and all available options:

Code
mvn -help

16. `mvn -f dir/pom.xml package`

Builds a project from a different location:

Code
mvn -f dir/pom.xml package

17. `mvn -o package`

Runs the Maven build in offline mode:

Code
mvn -o package

18. `mvn -q package`

Code
mvn -q package

19. `mvn -X package`

Displays the Maven version and runs the build in debug mode, showing all messages:

Code
mvn -X package

20. `mvn -v`

Displays the Maven version information:

Code
mvn -v

21. `mvn -V package`

Displays the Maven version and continues with the build:

Code
mvn -V package

22. `mvn -DskipTests package`

Skips the execution of unit tests during the build:

Code
mvn -DskipTests package

23. `mvn -Dmaven.test.skip=true package`

Also skips the execution of test cases:

Code
mvn -Dmaven.test.skip=true package

24. `mvn -T 4 clean install`

Executes the build with parallel threads to reduce build time:

Code
mvn -T 4 clean install

Maven Options

Maven also provides a variety of command-line options to customize the build process:

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie JavaScript
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren