Create

mvn archetype:generate

This will start an interactive process for generating the new project. There will be prompts for the groupId, artifactId, and version (among other things).

To skip the interactive method, use the following syntax instead:

mvn archetype:generate -DgroupId=ca.salmanfs.javaPractice -DartifactId=HelloWorld -DinteractiveMode=false

Compile

Maven built us a basic Java file that prints “Hello World!” We can compile that now:

mvn compile

This will execute the Maven build lifecycle phases of ‘validate’ and ‘compile’. This is what Maven is doing for us:

mkdir -p target/classes/
javac -d target/classes/ -cp src/ src/main/java/ca/salmanfs/javaPractice/App.java

Execute

java -cp target/classes/ ca.salmanfs.javaPractice.App

The -cp flag tells the Java interpreter where to find the package that we specify.