Backend Development 6 min read

Master Maven Archetype: Quickly Bootstrap Consistent Java Projects

Learn how to use Maven Archetype to create standardized project skeletons, customize templates, generate and share archetypes, and integrate them into IDEs, streamlining Java project initialization, reducing manual setup errors, and improving development efficiency across teams.

Dangbei Technology Team
Dangbei Technology Team
Dangbei Technology Team
Master Maven Archetype: Quickly Bootstrap Consistent Java Projects

Preface

In most enterprise software development ecosystems, project initialization follows a set of template standards, requiring integration of internal middleware, common code layers, and standard formatting. Traditional project startup copies an old project and manually adjusts package names and configurations, which is inefficient and error‑prone, increasing maintenance cost and risk.

Maven Archetype is a project template tool that lets us easily define the basic structure of a project, including necessary dependencies, configuration file templates, and specific code snippets, greatly simplifying project creation, reducing repetitive work, and ensuring consistency so developers can focus on core business logic.

What is Maven Archetype

Maven Archetype

is a template mechanism in

Maven

projects that can generate a template project based on an existing one, providing the skeleton structure—directories, files, and configurations—so we can quickly start a new project without writing everything from scratch.

How to customize an Archetype

Copy Maven's

settings.xml

to the

.m2

directory.

In the project root, run the Maven command:

<code>mvn archetype:create-from-project</code>

After successful execution, a

target

folder is generated in the project root.

Delete unnecessary folders under

target

(e.g.,

.idea

,

test

,

target

).

Copy

target\generated-sources\archetype

to a safe location to prevent accidental removal by

mvn clean

.

Open the copied project and modify the parent

pom

.

Add missing

module

entries.

<code>&lt;modules&gt;
    &lt;module&gt;${rootArtifactId}-adapter&lt;/module&gt;
    &lt;module&gt;${rootArtifactId}-app&lt;/module&gt;
    &lt;module&gt;${rootArtifactId}-client&lt;/module&gt;
    &lt;module&gt;${rootArtifactId}-common&lt;/module&gt;
    &lt;module&gt;${rootArtifactId}-domain&lt;/module&gt;
    &lt;module&gt;${rootArtifactId}-infrastructure&lt;/module&gt;
    &lt;module&gt;${rootArtifactId}-start&lt;/module&gt;
&lt;/modules&gt;</code>

Update the

dependencyManagement

section to reference each module as follows:

<code>&lt;dependency&gt;
    &lt;groupId&gt;${groupId}&lt;/groupId&gt;
    &lt;artifactId&gt;${rootArtifactId}-adapter&lt;/artifactId&gt;
    &lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;</code>

How to use an Archetype

In the modified archetype project root, run:

<code>mvn install</code>

After success, an

archetype-catalog.xml

file appears in the

.m2\repository

directory.

Add this file to IDEA’s

archetype catalogs

.

When creating a new project, select the added catalog and archetype, fill in project information, and create the project directly.

How to share an Archetype

In the archetype project root, run:

<code>mvn deploy</code>

Upload the generated

archetype-catalog.xml

to an OSS and obtain its URL.

Team members add this URL to IDEA’s

archetype catalogs

; the remaining steps are the same as above.

Conclusion

Maven Archetype

is a powerful tool that helps quickly create project skeletons, saving tedious configuration and initialization work. By customizing an archetype, teams can tailor templates to project needs and boost development efficiency. Adding the appropriate catalog and archetype in IDEA enables rapid project creation.

References

https://maven.apache.org/archetype/index.html

https://baeldung-cn.com/maven-archetype

javaBuild AutomationmavenArchetypeProject Templates
Dangbei Technology Team
Written by

Dangbei Technology Team

Dangbei Technology Team public account

0 followers
Reader feedback

How this landed with the community

login 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.