Mvn install vs jar: jar

What is the difference between the "mvn install" command and using jar: jar plugin?

Clearly, โ€œinstallโ€ seems to create a jar, and so I'm wondering what is needed for jar: jar plugin.

+4
source share
3 answers
Command

mvn install will run the maven life cycle before the installation phase. This means that all previous phases will be completed (including the phase of the packet).

In a simple maven jar project, the package phase is associated with the maven-jar-plugin. And therefore, the execution of mvn install will be executed at some jar:jar point.

+2
source

You can specify two types of things on the maven command line:

  • life cycle phases (they do not include the symbol :

  • (they include at least one character : depending on how fully you specified the plugin, it can be short-name:goal or groupId:artifactId:goal or groupId:artifactId:version:goal )

There are three life cycles : default, clean, and site. Each life cycle consists of a series of phases. When you specify a phase in the life cycle, Maven will complete all phases in this life cycle before and enable the specified phase.

When you specify a plugin target, that plugin target is called and only that point of the plugin.

Maven has a packaging concept that defines a set of default plugin bindings to the life cycle stages. For example, packaging jar (by default, if your pom.xml includes the <packaging>...</packaging> element) by default binds jar:jar to the package phase and binds install:install to the install phase.

So when you type

 $ mvn package 

Maven will work at all stages of the life cycle, executing plugins that are tied (either from the life cycle or by defining plugins in pom) as they progress.

When entering

 $ mvn jar:jar 

Maven will just launch the jar plugin. [/ p>

The life cycle is 99 times the 100 that you want to use.

This is how you usually want to refer directly to the goals of the plugin.

  • jetty:run to start the web server

  • surefire:test to quickly re-run tests (usually with -Dtest=... to indicate a specific

  • release:prepare release:perform to release your code

  • versions:... to perform some update or request content related to the version, for example. versions:display-plugin-updates

  • ship:ship or cargo:deployer-deploy to push your built artifacts to the hosting environment

+16
source

install puts the artifact in your local (on your computer) maven repository, jar:jar not. If you call jar:jar in a library, then try to reference this library in another project, it will not be in your local repository.

Also note that mvn package is a cleaner way to do packaging, rather than using jar:jar .

+2
source

All Articles