Maven Introduction


mvn archetype:generate -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

What does it do?

  • Execute the Maven goal archetype:generate, and passed in various parameters to that goal.
  • archetype is the plugin that provides the goal. (goal is something like an ant task).
  • archetype:generate goal creates a simple project based on maven-archetype-quickstart archetype.

What is a plugin

  • Collection of goals with a general common purpose
  • For example jboss-maven-plugin deals with various jboss items

mvn package

  • This is a phase rather than a goal.
  • Phase is a step in build cycle which is ordered sequence of phases.
  • When a phase is given, Maven will execute every phase in the sequence up to and including the one defined.
  • For example, if we execute the compile phase, the phases that actually get executed are:

Test your compiled and packaged jar

  • java -cp target/my-app-1.0-SNAPSHOT.jar

Java 9 or later

  • By default your version of Maven might use an old version of the maven-compiler-plugin that is not compatible with Java 9 or later versions.
  • To target Java 9 or later, you should at least use version 3.6.0 of the maven-compiler-plugin and set the maven.compiler.release property to the Java release you are targetting
    (e.g. 9, 10, 11, 12, etc.)

Maven Phases

  • validate – check if all the information is available
  • compile – compile the source code of the product
  • test – test complied code using suitable unit testing product
  • package – packagae the compiled code and package it in distributable format – jar
  • integration-test – process and deploy the package into an environment where integration tests can be run
  • verify – run checks to verify if the package is valid and meets quality criteria
  • install – install the package in local repository for use in dependency in other projects locally
  • deploy – done in an integration environment, copies the final package to remote repository for sharing with other developers and projects

Two special Maven phases

  • clean – cleans up artifacts created by prior builds
  • site – generates site documentation for this project

Phase Goal Relationship

  • Phases are mapped to goals
  • Specific goals executed per phase are dependent on packaging type of product.
  • Project type jar – package executes jar.jar
  • Project type war – package executes war.war

Phase & Goal execution order

  • Phases and goals can be executed in sequence
  • mvn clean dependency:copy-dependencies package

Maven Default Folders

  • src/main/java Application/Library sources
  • src/main/resources Application/Library resources
  • src/main/filters Resource filter files
  • src/main/webapp Web application sources
  • src/test/java Test sources
  • src/test/resources Test resources
  • src/test/filters Test resource filter files
  • src/it Integration Tests (primarily for plugins)
  • src/assembly Assembly descriptors
  • src/site Site
  • LICENSE.txt Project’s license
  • NOTICE.txt Notices and attributions required by libraries that the project depends on
  • README.txt Project’s readme

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!


Leave a Reply

Your email address will not be published. Required fields are marked *