Creating a Java project using Maven archetype

Luiz Gustavo De O. Costa
3 min readJan 27, 2022
Maven logo

1. Situation

Avoid the DRY (Don’t Repeat Yourself) when a new Java project should be created.

2. Task

New Java project is less error prone due to copy/paste from previous projects.

3. Action

Use the Maven archetype to create the projects, via command line or by IntelliJ.

3.1 Command line

An example of a Maven archetype site.

Maven archetype

Project structure, after running the mvn clean test command. Using Mac the zsh doesn’t have a tree program, then use this alias.

Well, there are some weird folders, right? Yes. Then you can create your own or choose another from the many options, as will be shown below.

3.2 IntelliJ

Create a new project and then select Maven, Create from archetype

IntelliJ New Project screen

Select the maven-archetype-quickstart:RELEASE

IntelliJ New Project — Select maven-archetype-quickstart:RELEASE

Fill/Change the values

Fill the project name and groupId, if any.

And hit the Finish button

Review the values and hit the Finish button

And then, the project is loaded. The Java version of this archetype is 1.7 (old). If you prefer, create your own archetype :).

IntelliJ Project structure

4. Result

As expected it is better to use an archetype rather than copy/rename files. Although, sometimes the archetype doesn’t fit well for you, so it is great to know how to tailor one for you.

5. References

--

--

Luiz Gustavo De O. Costa

Hey friend!! I’m Luiz Gustavo, a Java developer and I’m here to learn and write about Java, tests and good practices