Categories: Maven

Create New Project Using Maven In Eclipse

In last tutorial we learnt to configure maven in eclipse . In this tutorial we will learn to create new maven project in eclipse.
To create a new project in maven we need to follow following steps 
 
1) Open eclipse and follow stated navigation represented in below pic
2) A new pop- up will open , in that pop-up we need to check the provided option as below
 
 
 
3) Again a new pop-up will open, in that pop-up box we need to fill some information related to our project.
 
 
 
After filling required fields click finish button.
 
4) After clicking finish button you will find a new project being created in the project explorer.
 
 
5) You can see a new project has been created with symbol ‘M’ over the project which shows that it is maven project. 
 
6) You can see maven has provided the specified folder structure and a POM.xml file by his own. This is why maven is called as “Convention Over Configuration”.
 
7) POM.xml is heart of maven project.

 

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelversion>4.0.0</modelversion>

<groupid>com.dineshonjava.example</groupid>

<artifactid>maven_first_example</artifactid>

<version>0.0.1-SNAPSHOT</version>

<name>sample project</name>

<description>this project is being created for learning.</description>
</project>

 

8) The content of this pom.xml is being generated based on the information we have filled while creating the new project using maven.
 
9) By following Convention over configuration maven states that ” I am providing specific folder structure to put specific files, like : 
     src/main/java –> to put .java file
     src/main/resources –> to put resource files like properties file in class path
     src/test/java —> to put . java file for junit test cases.
 
10)  Now we will be writing simple Java program in src/main/java
package com.dineshonjava;
public class Example1 {
public static void main(String[] args) {
System.out.println("welcome to maven");

 }
}

11) Now we need to run the application, Before running the application we need to build that and to build that 
  a) right click on the project 
  b) click on the run as ‘maven install’ 
  c) after clicking that look into console , if every thing will be fine you will find following :
    

[INFO] 
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ maven_first_example ---
[INFO] Building jar: E:newsprinwsmaven_first_exampletargetmaven_first_example-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ maven_first_example ---
[INFO] Installing E:newsprinwsmaven_first_exampletargetmaven_first_example-0.0.1-SNAPSHOT.jar to C:Userslenovo.m2repositorycomdineshonjavaexamplemaven_first_example.0.1-SNAPSHOTmaven_first_example-0.0.1-SNAPSHOT.jar
[INFO] Installing E:newsprinwsmaven_first_examplepom.xml to C:Userslenovo.m2repositorycomdineshonjavaexamplemaven_first_example.0.1-SNAPSHOTmaven_first_example-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.271s
[INFO] Finished at: Tue Jun 16 23:35:35 IST 2015
[INFO] Final Memory: 7M/178M
[INFO] ------------------------------------------------------------------------
12) After running that process , when you will look into project explorer you will find following 

 

 
13) Due to above process which ease the building of project , maven is also famous as automated building tool.
 
14) Now to run this simple application just click on the project and run as a java application and you can find the desired output in console.
More we will learn about the different components of maven in upcoming tutorial .
Keep Learning, Happy Coding
Previous
Next
Anamika

Share
Published by
Anamika

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

3 years ago