Getting Started with Maven | Java Application Development | Specifying DarchetypeArtifactId
Maven can create many kinds of programs. For each one, the project creation steps and the pom.xml contents may differ. To develop with Maven, you need to know “how to create the program you want to build.”
Creating a Specific Project
As a basic example, let’s start with developing a Java application, meaning a Java program that can be run on an ordinary computer.
When creating a project with Maven, we ran the mvn archetype:generate command. This is the most basic way to create a project. However, when you run it, a long list of templates is displayed. You are supposed to select the template to use, but there are already more than 1,000 items, so choosing one is difficult.
In fact, you can specify the template to use in advance when creating a project. Use the -DarchetypeArtifactId option.
mvn archetype:generate -DarchetypeArtifactId=ArtifactID
This is how you call it. -DarchetypeArtifactId specifies the artifact ID of the template to use. In most cases, specifying the artifact ID is enough to identify the template.
However, in some cases it may not be possible to identify it uniquely, for example when multiple templates happen to have the same artifact ID. In that case, there is also an option called -DarchetypeGroupId for specifying the group ID. Use it as follows to make the selection definite.
mvn archetype:generate -DarchetypeGroupId=GroupID -DarchetypeArtifactId=ArtifactID
The Default Is maven-archetype-quickstart
So how should you specify a general Java application project? The basic command is as follows.
$ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
When you run it like this, the following output appears.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
Define value for property 'groupId': :
Define value for property 'artifactId': :
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': : :
[WARNING] Archetype is not fully configured
Define value for property 'groupId': : ^Ckimkcui-MacBook-Pro:mvn kimkc$
kimkcui-MacBook-Pro:mvn kimkc$ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
Define value for property 'groupId': : Enter group ID
Define value for property 'artifactId': : Enter artifact ID
Define value for property 'version': 1.0-SNAPSHOT: : (default)
Define value for property 'package': Group ID : : (default)
Enter the group ID, artifact ID, version, package, and so on in order. As you can see, these are the same values entered when creating the project earlier. Once you enter them, a Java application project is created.