CEIT Open Course Content

Apache Maven (Build tool)

Download software

Download the binary distribution.

  1. Apache Maven project website

Install

Installation steps

You will have to add the full path to the bin directory of your Maven extracted directory to the Path environment varialble of the operating system.

Quickstart sample project

  1. Run below command:

    mvn archetype:generate
    
  2. Except for groupId and artifactId, accept the defaults. Specify 'mypkg' as the groupId, "hello-world" as the artifactId. This will create a sample project that follows the quickstart archetype.
  3. Change directory to the newly created directory.
  4. To clean the project and build, run the below command:
    mvn clean package
    
  5. Check that the target directory will now contain the output jar file.

You can generate a project non-interactively by specifying details in one go as follows:

mvn archetype:generate -B -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=mypkg -DartifactId=hello-world

Windows users may have to quote the parameters as shown below:

mvn archetype:generate -B "-DarchetypeGroupId=org.apache.maven.archetypes" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DgroupId=mypkg" "-DartifactId=hello-world"

It's also possible to specify other parameters in the command line like the project version number, the quickstart archetype version and Java compiler version.

What else to try?

  1. Update the pom.xml file to specify the Java version (say to 25).
  2. Run 'mvn site' to generate website files for the project. Check the target/site directory for the generated content.
  3. Update the pom.xml file to specify the Java class with the main method so that the generated .jar artifact can be executed directly (As in 'java --jar target/hello-world-1.0-SNAPSHOT.jar).
  4. Create a Maven project based on the webapp archetype. Deploy to the Tomcat application server and check.
  5. Use Spring Initializr website to generate a Spring Boot application that uses Maven and check.