Common Maven Commands Explained (Including for Eclipse IDE)
Maven is a powerful build automation tool for Java projects. Whether you're using Maven via the command line or integrated with Eclipse IDE, the core commands remain the same. Here's a breakdown:
Common Maven Commands (Command Line & Eclipse IDE)
| Command | Description |
|---|---|
| mvn clean | Deletes the target/ directory. Ensures a clean build. |
| mvn compile | Compiles the Java source code in the src/main/java directory. |
| mvn test | Runs unit tests in src/test/java. |
| mvn package | Packages compiled code into a .jar or .war file. |
| mvn install | Installs the .jar or .war to your local Maven repository (~/.m2). |
| mvn deploy | Deploys the artifact to a remote repository (e.g., Nexus, Artifactory). |
| mvn site | Generates project documentation (using plugins). |
| mvn validate | Validates the project structure and checks for missing info in pom.xml. |
| mvn verify | Runs additional checks like integration tests. |
| mvn dependency:tree | Shows the project dependency tree. Helps find conflicts. |
| mvn help:effective-pom | Shows the fully resolved POM (with inheritance and profiles applied). |
| mvn archetype:generate | Creates a new Maven project from an archetype (template). |
Using Maven Commands in Eclipse IDE
Eclipse IDE (with M2E Plugin—Maven integration) allows you to run Maven commands without using the terminal.
To Run Maven Goals in Eclipse:
Right-click on your Maven project in Project Explorer.
Choose Run As > Maven build...
In the Goals field, enter one or more of the following:
cleancompilepackageinstalltestsite
Click Run.
After adding dependency in pom.xml, we should update project, as shown below:
Right-click → Maven →
Update Projectto refresh dependencies.
We can also execute maven commands from command line from project workspace.
go to project workspace and open cmd terminal and execute below command:
mvn clean install
go to project workspace and open cmd terminal and execute below command:
mvn clean install
No comments:
Post a Comment