Skip to content

Maven Archetype Quickstart

Zhamri Che Ani edited this page Oct 24, 2019 · 1 revision

Generate Maven Project:

$ mvn archetype:generate

archetype:generate

  1. Archetype (Type of Development: eg. web, spring)
  2. Group ID (package/folder directory)
  3. Artifact ID (Project Name)
  4. Version
  5. Package (Jar file)

Generate Simple Project:

$ mvn archetype:generate -DgroupId=com.zhamri.stiw3054 -DartifactId=HelloMavenApp -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=1.0-SNAPSHOT -DinteractiveMode=false

Result: Generated Files

pom.xml  
/src/main/java/com/zhamri/stiw3054/App.java  
/src/test/java/com/zhamri/stiw3054/AppTest.java  

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.zhamri.stiw3054</groupId>
  <artifactId>HelloMavenApp</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>HelloMavenApp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

App.java

package com.zhamri.stiw3054;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

AppTest.java

package com.zhamri.stiw3054;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}

References:

  1. https://www.tutorialspoint.com/maven/maven_project_templates.htm
  2. https://maven.apache.org/archetypes/maven-archetype-quickstart/
  3. https://maven.apache.org/archetypes/maven-archetype-simple/