DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • A Maven Archetype for Jakarta EE 10 Applications
  • Creating a Maven Archetype From an Existing Project
  • Using Python Libraries in Java
  • DGS GraphQL and Spring Boot

Trending

  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • Introduction to Retrieval Augmented Generation (RAG)
  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  • ITBench, Part 1: Next-Gen Benchmarking for IT Automation Evaluation
  1. DZone
  2. Coding
  3. Java
  4. Creating a Maven Archetype

Creating a Maven Archetype

Read this tutorial in order to learn how to create a Maven archetype from an existing project. This person uses Eclipse IDE to create the Maven project.

By 
Anupam Gogoi user avatar
Anupam Gogoi
·
May. 17, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
18.8K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Many times we need to create a Maven archetype to distribute the project template. Here in this article, I am going to describe how easy it is to create a Maven archetype from an existing project.

Create a Maven Project

First of all, let's create a very simple Maven project. I am using Eclipse IDE to create the Maven project. Here is the pom.xml file of the project:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.porua</groupId>
    <artifactId>archetype-porua</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>com.porua</groupId>
            <artifactId>porua-container</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.196</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>make-fat-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                    <execution>
                        <id>zip-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assembly/assembly.xml</descriptor>
                            </descriptors>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>porua-repo</id>
            <name>Porua Repository</name>
            <url>https://github.com/anupamgogoi0907/porua-docs/raw/repo</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
</project>

Now go to the root directory of the project and execute the following commands in sequence:

  • mvn archetype:create-from-project

This command will generate the archetype from the existing Maven project. You can check the generated files at the following location:

target/generated-sources/archetype

Image title

Now at this point, you can do two more important things:

  • Modify the target/generated-sources/archetype/pom.xml to add extra things if you need
  • Modify target/generated-sources/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml to include/exclude files etc in the archetype. (Please read Maven's official documents for more information)

mvn clean install

Execute this command on target/generated-sources/archetype/pom.xml. It will install the plugin in your local repository.

mvn archetype:generate -DarchetypeCalalog=local

Execute this command to check your archetype available in the local repository.

Using The Archetype

At this point, our archetype is installed successfully in our local Maven repository. Let's try to make use of it. Use this command to make a project from the archetype:

mvn -B archetype:generate \
-DarchetypeGroupId=com.porua \
-DarchetypeArtifactId=archetype-porua-archetype
-DgroupId=com.mycompany.app \
-DartifactId=my-app

Conclusion

That's it. It's very simple to create a Maven archetype from an existing project.

Archetype (information science) Apache Maven

Opinions expressed by DZone contributors are their own.

Related

  • A Maven Archetype for Jakarta EE 10 Applications
  • Creating a Maven Archetype From an Existing Project
  • Using Python Libraries in Java
  • DGS GraphQL and Spring Boot

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!