After the successful installation of the Maven.
Let us create a new project template using maven.
mvn archetype:create -DgroupId=com.example -DartifactId=SimpleExample -Dpackagename=com.example
The result will be
To work on the project you can import the project into eclipse. to create the files required by eclipse execute the below command in the project directory.
mvn eclipse:eclipse
The directory structure that will be cretaed will look like
Now just write your source code in the src folder.
To compile the project
mvn compile
To run test casesmvn test
To create the jar for the application, which will add the jar of the application in maven reposiroty
mvn install
The result will be
\M2_Repository\com\example\SimpleExample\1.0-SNAPSHOT\SimpleExample-1.0-SNAPSHOT.jar
You can even run multiple golas in one cmmand like
mvn compile test install
Now you can use this jar in any other application byshowing a dependency on this project as given below in pom.xml
<dependency>
<groupid>com.example</groupid>
<artifactid>SimpleExample</artifactid>
<version>1.0-SNAPSHOT</version>
</dependency>
If your project is having any dependency on any other then you need to show the deendency on it as below. example junit
<dependencies>
<dependency>
<groupid>junit</groupid>
<artifactid>junit</artifactid>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>