Difference between package and install command in maven


This is an short tutorial on Difference between package and install command in maven.

You can check my other posts on maven commands.

clean, package and install are the goal phases of maven life cycle.

Before that first understand the maven life cycle goals on the order execution.

maven default life cycle goals execution order

  • validate: validate checks all the valid information of an maven application
  • compile: Compile source code into class files i.e java to class files which also includes test classes (java and test folder java files)
  • test: Running test classes located in src/main/test folder
  • package: package the output of compiled source code and output is JAR,WAR,EAR files.
  • verify: Checks integration test and verify the result
  • install: This installs the jar/war file into local repository, so that other projects can use these as an dependency.
  • deploy: This deploy artifact jar/war into remote repository.

Maven clean life cycle

  • pre-clean: execute the validation before clean goal
  • clean : delete the previous build files located in target folder
  • post-clean : execute the validation tasks after clean goal

difference between mvn clean install and mvn clean package?

clean goal in both commands cleans and removes previous build files, It removes target folder of an maven project.

mvn clean package goal: This goal packages the project and output jar/war/ear file based on pom module.

if your pom.xml contains package=jar, It creates jar package if it is war package, it generates war package.

goal runs the below goals execution order

validate -> compile -> test -> package

maven clean install goal installs the artifact to local repository, so that other projects or applications can make this as an dependency and use in their projects.

Here is an order of execution

validate -> compile -> test -> package -> verify - install

install goals execution comes after package goal

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.