Convert dynamic web project to maven project
I used to be a VC programmer in past 10 years. Recently I start to do coding on java servlet that deployed on Tomcat. At first I even don’t know maven. So my project is growing with pure dynamic web project configuration.
The dependencies is annoying as my project growing. I decide to utilize maven to make my future more glowing. If you had the same problem and occasionally see this post, I bet you are a lucky guy.
Original configuration of my project is as the following:
Now let’s go thru it, the steps to convert are as the following:
1. Right click on your project in “Project Explorer”, tap “Configure -> Convert to maven project”.
2. Tap finish in the dialog if you would like to use the default setting.
3. Edit “.settings/org.eclipse.wst.common.project.facet.core.xml“ in your project folder. Make sure version is corresponded to the one in your original configuration.
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
4. Edit web.xml. make sure the web-app tag is ref to servlet 3.1
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
5. Edit pom.xml, add dependency of java servlet 3.1
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
  <scope>provided</scope>
</dependency>
6. Right click on your project in “Project Explorer”, tap “Maven-> Update Project”. Choose your project and tap “OK”
Now let’s run it on tomcat and I believe it works.