Basic Java Maven Archetypes
This is a collection of basic Maven Archetypes to create simple projects with Java and updated libraries.
Basic Java 8 / Java 9 Archetype
The first of the archetypes released to Maven Central by The Practical Developer is the Basic Java Archetype. This is what you’ll get with it:
- Choose between Java 8 or Java 9 when creating your project and get it configured into your
- Have a real-life
pom.xmlfor your project:
- Not only a recent version of JUnit 4 but also AssertJ and Mockito, proven as essentials.
- Included configuration and Manifest file to make your JAR executable.
- Coverage reports out-of-the-box with the included JaCoCo configuration.
- Get a basic
App.javafile with an executable
main(), and a test skeleton
AppTest.javawith a dummy test method showing a given-when-then structure.
This archetype is a modern alternative to maven-archetype-quickstart, which is even giving hints in the console about what you should expect – forget about the project created from Old (1.x) Archetype message.
How to use it
To create a basic Java 8 project using this archetype, execute:
mvn archetype:generate -DgroupId=[your-project-groupId] -DartifactId=[your-project-name] -DarchetypeGroupId=com.thepracticaldeveloper -DarchetypeArtifactId=archetype-java-basic-tpd -DarchetypeVersion=1.0.0
Typically, you set your project id to your namespace (something like com.yourcompany) and you give a good name to your project. Maven will ask you to confirm the details and you’ll have your basic project ready for you to start shining.
If you want to use Java 9, you can either input that option when prompted or pass the property directly with this command:
mvn archetype:generate -DgroupId=[your-project-groupId] -DartifactId=[your-project-name] -DarchetypeGroupId=com.thepracticaldeveloper -DarchetypeArtifactId=archetype-java-basic-tpd -DarchetypeVersion=1.0.0 -Djava-version=9
Note that you don’t need to download anything but Maven, since this archetype is already in the Maven Central Repository.