First of all you need to check if you have maven installed
mvn -v
This is something what you should see
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 1.8.0_191, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-15-generic", arch: "amd64", family: "unix"
You should see version of maven installed, version of your java, version of OS that you using. In my case it was maven 3.5.2 open jdk 8 and linux OS.
Maven is plugin based tool. To create new project you will need to use archetype plugin with goal generate. More specifically it will look like:
mvn archetype:generate
-DgroupId={project-goup}
-DartifactId={project-name}
-Dversion={initial version of project}
-DarchetypeGroupId={maven-template-group}
-DarchetypeArtifactId={maven-template-name}
Maven operates with 2 categories when it comes to projects. First is group which is represented by groupId. It has package style naming. Example: net.mendzeleu. Second is artifact which is represented by artifactId. This is basically name of the project. The idea is that combination of groupId and artifactId should uniquely identify all projects on the planet. 🙂 That’s why it is recommended to have company name or individual name in group id.
Same concept is applicable to archetype which is basically templates for the projects. Here are few useful archetypes:
org.apache.maven.archetypes:maven-archetype-quickstart – simple java project
mvn archetype:generate -DgroupId=net.mendzeleu -DartifactId=lib -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart
It will create structure as displayed below
org.apache.maven.archetypes:maven-archetype-webapp – simple web project
mvn archetype:generate -DgroupId=net.mendzeleu -DartifactId=weblib -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp
It will create structure as displayed below
Please make sure you have internet connection before you first time compile your project. Maven will try to download all dependencies and required plugins automatically.
To compile your project, execute following command in root folder of your project:
mvn clean install