This post explains how to setup an Spring MVC project in Eclipse.  Assuming that you have already know at least a bit  about Maven and Spring-MVC. Lets directly dive into the steps of doing the setup.

Steps.

1. Open Eclipse and go to File > New > Maven Project.

 New Maven Project Eclipse

 

2. Choose the work-space location where you want to setup the new project. In my case I have left it to the default workspace location and click Next

2014-11-28 06_24_32-Spring - Spring Tool Suite

 

3. On the next screen you'll be asked to choose the archetype for your project. An archetype is a template project containing default types for your project. Since want to create a spring-mvc. Site Search for spring-mvc in the filter and select the following archetype shown in the result.

Group Id: co.ntier

Artifact-Id : spring-mvc-archetype

Version : 1.0.2

2014-11-28 06_41_58-Spring - Spring Tool Suite

4. Next screen will ask you to enter some details regarding the project you are creating.

2014-11-28 06_43_46-Spring - Spring Tool Suite

Group Id: This is used to identify your project uniquely across all projects, this is generally your com.company.name

Artifact Id: This is usually the name of the new project / application you are going to create.

Package: This is the parent name of the package in which your java source will be generated.

After filing these details click Finish.

5. It will take Eclipse few seconds to generate the Project for you with default template files; After which you can see the project created in your work-space with following default files and folders.

2014-11-28 07_07_53-Spring - 2015cricketcup_src_main_java_com_cricketcup_controller_HomeController.j

 

src/main/java : This is your source folder which will have your java packages and source files.

Maven Dependencies:  This will contain jar files that your project is dependent on, Since we created spring-mvc project, It will have all spring jar's required to run a spring project.

src: This will contain your web application views and assets (images, css, js)

pom.xml : This is the configuration file

You will need an Application Server installed on your machine, to run the project.  Right click on the project select Runs As and choose Run on Server. Select the desired server to run the project.

2014-11-28 09_11_08-Spring - http___localhost_8080_2015cricketcup_ - Spring Tool Suite

 

Note: In STS after step 4 , you might receive this error Unable to create project from archetype [co.ntier: spring-mvc-archetype..]

Delete your .m2/repository/ directory and follow the steps again. This should solve this error.

OR

change Repository URL to: Repository: http://repo.maven.apache.org/maven2/

2014-11-28 07_01_20-Spring - Spring Tool Suite

 

Comments