DEV Community

Cover image for How to create a maven archetype in 5 minutes
Luiz Gustavo Costa
Luiz Gustavo Costa

Posted on

1 2

How to create a maven archetype in 5 minutes

Table Of Contents

Why

Use a template project structure in order to speed up your project definition such as packages, dependencies and relationship between classes.

How to build

To build an archetype you should follow the rules

  • The packing of project should be maven-archetype

  • Create a file archetype-metadata.xml under the folder src/main/resources/META-INF/maven.
    This file is responsible to move the files classes, folders etc.

  • The folder src/main/resources/archetype-resources should have all files to be generated by this archetype.

Project expanded

Structure

Below look the structure desired

Project structure archetype

After open the project generated you can check the classes packages and so on

Generated project

Benefits

  • The benefits of using a archetype as said before is speed up your project creation but also to maintain the projects with the same structure and avoid copy and paste of files.

How to run?

  • use the maven to build your archetype and for that execute the command

    mvn instal

    for instance asciicast

  • Once your template is created it's time to create your project with the template

mvn archetype:generate -DgroupId=com.mynewcompany -DartifactId=new-project -DarchetypeGroupId={from your archetype project} -DarchetypeArtifactId={from your archetype project}

asciicast

References

https://github.com/luizgustavocosta/maven-archetype-costa-luiz
https://maven.apache.org/guides/introduction/introduction-to-archetypes.html
https://pixabay.com/photos/blueprint-ruler-architecture-964629/

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay