Creating a Java project using Maven archetype

Maven logo

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

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

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

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.

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

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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store