How to Create a Maven project and design MVC framework

Today, We are going to see how to create a maven project to develop a Java web application and how to design MVC framework.

Create a Web project in eclipse using Maven.

Before creating a project make sure, JDK is installed in your machine. I am going to use the STS tool in this whole tutorial series. You can use the STS or eclipse it will work in the same manner.

Steps to create a maven project

1) Launch Eclipse.

2) To create a new Maven project Go to New==>File==>Other==>

 

3) Search for “Maven” and select the “Maven project” click to the Next button.

 

 

4) Select the workspace where you want to save the project and click the Next button.

 

 

5) Select Maven archetype for maven “maven-archetype-web app” and Click to the Next button.

 

6) Enter the Group Id and project name and click on the Finish button.

 

 

7) A basic java application is created by maven and did you notice it’s using java 1.5 that we have to change into 1.8 or higher.

 

How to change the Java version for existing maven project

1) Right-click on the project and navigate to build path ==> configure build path.

2) Click to “Project facets” and click to “convert to faceted form”

 

3) Select the Java version as 1.8 and click to apply the changes

4) Move to Java build path and click to Libraries tab and edit the “JRE System Library”

5) Change it into 1.8 and click to finish.

 

6) Click to the Oder and Export tab and check all the unchecked checkbox and click to apply and close.

Now, the basic web application is ready. Let’s see how can we run the application and check the “Hello World!” as output.

Run the Java web application over the Tomcat server

Server configuration

Step 1) Download tomcat 8.5 >>Download Tomcat >>

Step 2) Extract File and copy at any location in your machine for example “C drive”.

Step 3) Again Switch to sts tool/Eclipse and search for server window. Follow the path to find server window

=>Windows=>Show view=>Others=> Server.

Step 4) Right-click in the server window and select.

New=>server=>Apache=>Tomcat 8.5 Server=>Next.

Step 5) Browse the tomcat folder which we had copied in “C drive”.

Step 6) Click to Next and Finish.

Run the application

Step 1) Right Click on the project and click Run As ==> Run on Server.

Step 2) Select the option “Manually define a new server”, select the tomcat version and click to NEXT button.

Step 3) Browse the tomcat server form the location and click to finish.

Step 4) Run successfully now check the output over the browser.