How to Quickly Bootstrap Java Projects with Maven Archetype Templates

This guide explains how to use Maven's archetype plugin to create, customize, install, and share project templates, enabling rapid initialization of new Java projects while excluding unwanted files, and shows both command‑line and IntelliJ IDEA integration for consistent backend development.

Programmer DD
Programmer DD
Programmer DD
How to Quickly Bootstrap Java Projects with Maven Archetype Templates

Integrating Maven Archetype Plugin

First add the Maven archetype plugin to the template project's pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-archetype-plugin</artifactId>
    <version>3.2.0</version>
</plugin>

Generating a Template from an Existing Project

Run mvn archetype:create-from-project in the project root; the archetype is created under target/generated-sources/archetype. Unwanted files such as .iml and .idea can be excluded via an .properties file:

# Archetype coordinates must be declared
archetype.groupId=cn.felord
# Prefer ending with -archetype
archetype.artifactId=template-archetype
archetype.version=1.0
# Files/folders to ignore, comma‑separated
excludePatterns=**/.idea/**,**/*.iml

Generate the archetype with:

mvn archetype:create-from-project -Darchetype.properties=./archetype.properties

Installing the Archetype Locally

Navigate to target/generated-sources/archetype and execute mvn install. The archetype is registered in the local ~/.m2/archetype-catalog.xml:

<archetype-catalog>
  <archetypes>
    <archetype>
      <groupId>cn.felord</groupId>
      <artifactId>template-archetype</artifactId>
      <version>1.0</version>
      <description>spring security learning demo</description>
    </archetype>
  </archetypes>
</archetype-catalog>

Creating a New Project from the Local Archetype

Run:

mvn archetype:generate -DarchetypeCatalog=local

or use a full command line with parameters:

mvn archetype:generate \
  -DgroupId=cn.felord.demo \
  -DartifactId=demo-project \
  -Dversion=1.0.0 \
  -Dpackage=cn.felord.demo \
  -DarchetypeGroupId=cn.felord \
  -DarchetypeArtifactId=template-archetype \
  -DarchetypeVersion=1.0 \
  -DinteractiveMode=false
Remove -DinteractiveMode or set it to true to use the interactive wizard.

Sharing the Archetype via a Remote Repository

Add a remote repository with deploy permission to settings.xml, then deploy the archetype:

mvn deploy

Configure the repository in settings.xml:

<repository>
  <id>archetype</id>
  <url>https://repository.domain.com/path/to/repo/</url>
</repository>
<server>
  <id>archetype</id>
  <username>repousername</username>
  <password>xxx.felord.cn</password>
</server>

Using the Archetype in IntelliJ IDEA

In IDEA, choose New Project → Maven, check “Create from archetype”, click “Add Archetype”, fill in the coordinates, and finish the wizard.

Project template generation helps maintain consistency across Java projects and is an essential skill for aspiring Java architects.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaBuild AutomationBackend DevelopmentArchetypeProject Template
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.