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.
1. Open Eclipse and go to File > New > Maven Project.
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
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
4. Next screen will ask you to enter some details regarding the project you are creating.
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.
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.
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.
change Repository URL to: Repository: http://repo.maven.apache.org/maven2/
- Archetype Group Id: co.ntier
- Archetype Artifact Id: spring-mvc-archetype
- Archetype Version: 1.0.2
- Repository URL: http://repo.maven.apache.org/maven2/