Creating a Java project using Maven archetype
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.
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
Select the maven-archetype-quickstart:RELEASE
Fill/Change 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 :).
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.