Prerequisites and Assumptions
This document assumes that the following software packages have already been installed and properly configured on your system:
- A version of the Java SE Development Kit (JDK)
- Apache Maven
- A local instance of Apache Tomcat, version 7.0 or greater
- Eclipse IDE
- m2eclipse, an Eclipse plugin for Apache Maven support
Next, we will use a Maven archetype to generate a new web application project.
In Eclipse, create a new Maven Project. File > New > Other... > Maven Project.
In this first screen shown above, you can typically accept the defaults and click Next >.
Find and select the maven archetype called maven-archetype-webapp, as shown above, and click Next >.
Complete the fields shown above as appropriate to your own project. The Artifact Id is going to be your project's name in Eclipse (and typically the app context in the URL to your web app). Typically, the Group Id and Artifact Id combine to make the base package.
You should then end up with the following project structure in the Eclipse Package Explorer view:
At this point, you may notice that you cannot add the web app project to the Tomcat server that's in the Eclipse IDE's Servers view when you right-click on the server and select Add and Remove..., so let's fix that.
Right-click on the project in the Eclipse Project Explorer view and select Properties. When the Properties dialog appears, select the Project Facets item.
Click the link to Convert the project to faceted form as shown above.
Check the Dynamic Web Module facet, as shown above.
You'll then see that a yellow info box shows, which says "Further configuration available...". Click that.
Make sure the Content directory is set to src/main/webapp as shown above and click OK. Click any remaining Apply/OK buttons to apply and close out the project Properties dialog.
Now, you should be able to right-click on your Tomcat server in the Servers view of the IDE, choose Add and Remove... and add the project.
You can also verify this by right-clicking on the server and select Start to start it up.
Once started, access http://localhost:8080/yourAppContext in the browser and you should see the Hello World! JSP page that was created in the Maven Web App archetype.