Maven can be as simple or as complicated as you’d like. The maven command line interface is mvn. You can quickly find the version using the –version option:
mvn –version
This is useful for a lot, but most notably to see where Maven is, which is in the home line. You can then create a project by using the archetype:generate option. Let’s say I wanted to create an artifactID of Precache with a standard environment (DarchetypeArtifactId) that doesn’t need to be interactive. That would look as follows using the mvn command:
mvn archetype:generate –DgroupId=com.precache –DartifactId=precache –DarchetypeArtifactId=maven–archetype–quickstart –DinteractiveMode=false
This creates a directory in Maven with a full hierarchy that matches what maven will need (a faux root) for each app created. The pom.xml file is created in the root of the faux root and outlines metadata for the project as well as dependencies. Next, copy any source code into ../src/main/java (where .. is the faux root of the maven project) and any source test code into ../src/test/java.
Once the files are where they need to be it’s as easy as running mvn with the package verb to package it all up:
mvn package
That creates the jar file. Next, create a site:
mvn site
And between steps, do a little housekeeping:
mvn clean dependency:copy–dependencies package
Run your unit tests with the test verb (super-hard to remember):
mvn test
And check to see if your test sources compile use the test-compile verb:
mvn test-compile