EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Software Development Software Development Tutorials Maven Tutorial Maven Build Command

Maven Build Command

Maven Build Command

Introduction to Maven Build Command

The maven build command is used in a project management tool based on the project object model, and it is used in dependency, documentation, and project build. It is a tool used for managing and building the project, which was java based. This is used to easier the work of java developers working on the building project.

Overview of Maven Build Command

We are using the build command when building the project from the command line. We are executing this command from where our pom file exists. We are passing the goal or phase of the life cycle as a parameter to this command. Maven is reading the pom file and resolving the project dependencies. These are validating dependencies from the local repository; suppose it is available, then we can use the same.

ADVERTISEMENT
Popular Course in this category
MAVEN Course Bundle - 10 Courses in 1 | 6 Mock Tests

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Suppose the dependency is not available, then into the build reactor of our local repo, then maven will be downloading the dependent artifacts from the central repository from the specified to the local repository. Maven executes all the life cycle phases until a specified will exists. Suppose the clean install command of maven is triggered at the time of jar packaging, then this will include the sources compilation executing tests from compiled files from jar files. Then install phase will install the resulting artifact from the local repository.

Key Takeaways

  • The maven will contain the multiple commands which were we are executing. Maven is a build of a life cycle, build goals, and build phases.
  • Maven is a widely used project model to manage and build projects based on maven.

Types of Maven Build Command

Below are the types of maven commands which were used at the time of the building project as follows.

1. mvn –version

To check the installed version of maven we are using the below command. This command will be printing the maven as well as the java version which was, which we have installed on the server. In the below example, we can see we are using two commands for checking the version of maven.

mvn –version
mvn –V

Maven Build Command mvn --version

2. mvn clean

The maven clean command is used to clean and removes the project and files which were generated from the previous build as follows. The maven clean command will first be downloading all the dependencies which were required for our project.

mvn clean

Maven Build Command mvn clean

3. mvn compile

The maven compiles command is used to compile the source code of the project. The maven compiles command will first be downloading all the dependencies which were required for our project.

mvn compile

Maven Build Command mvn compile

4. mvn test-compile

This command is used to compile the test source code from our project as follows.

mvn test-compile

mvn test-compile

5. mvn test

This Command is used to run the test of our project, we will running test module as follows.

mvn test

mvn test 1

mvn test 2

6. mvn package

This command is used to create jar or war file of our project for converting the same into file format which was distributable.

mvn package

mvn package 1

mvn package 2

7. mvn install

This command is used to deploy the war or jar files into the local repository as follows.

mvn install

mvn install 1

mvn install 2

8. mvn deploy

This command is used to copy the packaged jar or war files from the remote repository after compiling or building a project.

mvn deploy

mvn deploy

9. mvn pre-clean

This command is used to clean the project before building the project.

mvn pre-clean

mvn pre-clean

Maven Build Command Structure

The maven build command consists the two elements. First is the mvn and the other is the build phase, build goals and build life cycle. Below is the structure example as follows. The below command shows the maven command to execute by using the build cycle as follows.

mvn clean

Maven build command Structure 1

In the below example, we are installing the clean life cycle with the install build phase which is default as follows.

mvn clean install

Maven build command Structure 2

Maven build command Structure 3

Life Cycle of Maven Build Command

Below is the representation of the maven build command life cycle as follows. It will consist the below steps.

Life Cycle maven build command

  • Validate: This phase is used to validate the structure of the project is correct or not, it will check all the dependencies are downloaded or not.
  • Compile: This phase is used to compile the source code and convert the java files to class and it will be storing the classes in the folder.
  • Test: This phase is used to run the unit test.
  • Package: This step packages the compiled code into the format which was distributed like a war or jar file.
  • Integration test: In this phase, we are running the integration test on a specified project.
  • Verify: This step will run a check to verify that our project is valid and it will meet all the standards.
  • Install: This step will install the packaged code from the maven repository which was local.
  • Deploy: It will copy the packaged code from the repository which was local.

Maven is following the sequential order for executing the command where we are running all steps from n number of steps. It will be verifying the project along with the test of integration.

Maven Build Command Test

The maven test command is used to run the specified test from the project. The below example shows how we can run the test as follows.

mvn test

Maven build command Test 1

Maven build command Test 2

The below example shows how we can compile and test the source code from the maven build command as follows.

mvn test-compile

Maven build command Test 3

Maven Command Line Options

To find the command line options of maven we need to execute the help command with the maven command as follows. At the time executing the help command with maven it will be printing the below result as follows.

mvn –help

mvn –help 1

mvn –help 2

The below example shows we are using the –o option with the mvn package command as follows.

mvn –o package

mvn –o package

The below example shows we are using the –q option with mvn package command as follows.

mvn –q package

mvn –q package

The below example shows we are using the –X option with mvn package command as follows.

mvn –X package

mvn –X package

FAQ

Given below are the FAQs mentioned:

Q1. What is the use of the maven build command in the java project?

Answer: Maven contains multiple commands, by using those commands we are managing the project source code.

Q2. Which phases are involved in the life cycle of maven build command?

Answer: The maven build contains the eight phases into it, i.e. install, deploy, compile, validate, test, verify, integration test, and package.

Q3. How can we find the command line options for the maven build command?

Answer: We are finding all usable options of the maven build command by using a command of maven –help.

Conclusion

At the time of building the maven project from the command line, we are using the maven build command. The maven build command is used in a project management tool based on the project object model and is used in dependency, documentation, and build of the project.

Recommended Articles

This is a guide to Maven Build Command. Here we discuss the introduction and types of Maven Build Command along with structure, life cycle, test, and options. You may also have a look at the following articles to learn more –

  1. Maven Profile
  2. Maven Jar Plugin
  3. selenium maven dependency
  4. Maven Local Repository
ADVERTISEMENT
GOLANG Course Bundle - 6 Courses in 1
23+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
iOS DEVELOPER Course Bundle - 61 Courses in 1
147+ Hours of HD Videos
61 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
JAVA SERVLET Course Bundle - 18 Courses in 1 | 6 Mock Tests
56+ Hours of HD Videos
18 Courses
6 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
RED HAT LINUX Course Bundle - 5 Courses in 1
28+ Hours of HD Videos
5 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW