Here’s how to create a bare bones Java application using Apache Maven (v3.0.3 at time of writing).
The Command Explained
mvn : Maven command
archetype:generate : Maven goal
-DinteractiveMode=false : Use all default values.
-DarchetypeGroupId=org.apache.maven.archetypes : Tells maven where to look for project templates.
-DgroupId=com.trcooke.mvndemo : Root package name of your Java project
-DartifactId=maven-demo : Project module name. Directory of this name is created for the project.
The Command Output
The project structure
Maven’s the default version of jUnit is pretty old so I would recommend updating to the latest version, which is currently 4.11 but check on maven.org
The stub class
We have a simple ‘Hello World!’ implementation of a Java class created for us.
The stub jUnit test
Worth noting that this test is for jUnit version 3.x where we are extending junit.framework.TestCase. Using jUnit 4.x we use the @Test annotation on the test method instead. We also do not need the constructor or the suite() method which simplifies things considerably.