My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Wednesday, November 23, 2016

Where/How to create web.xml : Eclipse project - (Example using Jersey in Java)


Tip: Dynamic Web Project - - > RightClick - - > Java EE Tools - - > Generate Deployment Descriptor Stub. This would create Web.xml

Starting all over again from the question:
If you are doing Java programming to create some Service using Jersey or any other framework, you will many times land into situation where you need Web.xml to be created. I had once wondered where this file would be present. Or, better say, how should i create the Web.xml file.

Note that the web.xml file should be listed right below the last line in your screenshot and resides in WebContent/WEB-INF. 


If it is missing you might have missed to check the "Generate web.xml deployment descriptor" option on the third page of the Dynamic web project wizard.


Tip: Dynamic Web Project - - > RightClick - - > Java EE Tools - - > Generate Deployment Descriptor Stub. This would create Web.xml


A sample content of Web.xml can be as follows:



<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">
   <display-name>User Management</display-name>
   <servlet>
      <servlet-name>Jersey RESTful Application</servlet-name>
      <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
         <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.tutorialspoint</param-value>
         </init-param>
      </servlet>
   <servlet-mapping>
   <servlet-name>Jersey RESTful Application</servlet-name>
      <url-pattern>/rest/*</url-pattern>
   </servlet-mapping>
</web-app>


Take Care.
- Mohd Anwar Jamal Faiz

No comments:

Post a Comment