Sunday 21 February 2016

Eclipse: Missing web.xml file? How can I create web.xml in Eclipse?

Have you created Dynamic Web Project and created servlet and still are you missing web.xml file under \WebContent\WEB-INF\..?
Eclipse allows you to NOT create a web.xml file when you create Dynamic Web Project for Java EE 6, since the Java EE 6 spec (in general) and Servlet 3.0 spec (in particular) attempt to de-emphasize deployment descriptors.
You can use annotation to provide all the data that had been included in the web.xml file. You should read through the Servlet 3.0 spec from the jcp.org site to get a bit more explanatory text.
To change the url-mapping for a Servlet 3.0 servlet, the first place to look is in the source code for the servlet. Look for (and change) the value of the urlPatterns element.
If you are trying to create a web app based on Servlet 3.0, try to avoid creating a web.xml file.
But still if you need web.xml then you can do it by Dynamic Web Project –> RightClick –> Java EE Tools –> Generate Deployment Descriptor Stub.
Java EE Tools and Generate Deployment Descriptor Stubs
You should see web.xml file immediately after that.
Web.xml file for Dynamic Web Project
Now it’s time to deploy project to Tomcat Web Server. Right click on Server and click Add and Remove.
Tomcat Server - Add Remove Project
Then add your recently converted Dynamic Web project to Configured section at right and you should be all set.