Customizing web.xml files for Web Archive (WAR) files
You can customize the web.xml file that the workbench uses in the WAR file that the workbench builds for your Web service. You might want to change the web.xml by adding some filters for requests coming into your web service if you want these filters to be deployed along with the service. You might also want to add additional servlets or servlet mapping tags.
Although a web.xml file exists in the project for your Web service, you do not edit the web.xml file directly. Instead, you create a template that contains the changes that you want the workbench to include in the web.xml file when the workbench generates the WAR file again.
When you use the
Build and Deploy wizard to generate a WAR file, the workbench deletes all of the files in your project and recreates them. Therefore, if you edit the web.xml file directly, you lose your changes when you use the
Build and Deploy wizard.
When you use a template that contains the edits that you want to make to the web.xml file, the workbench merges the content of that template with the content web.xml file that it creates.
To customize a web.xml file:
- Open the
Navigator view, if it is not already open.
- Select
Window | Show View | Other.
- In the
Show View window, select
General | Navigator.
- Right-click the .metadata folder for your project and select
New | Other. In the
New wizard, expand
General and select
Folder. Click Next. On the
New Folder page, type templates as the name. Click Finish.
- Right-click the templates folder and select
New | Other. In the
New wizard, expand
General and select
Folder. Click Next. On the
New Folder page, type j2ee as the name. Click Finish.
- Right-click the j2ee folder and select
New | Other. In the
New wizard, expand
General and select
File. Click Next. On the
New File page, type web_template.xml as the name. Click Finish.
- In the editor for the new file, select the Source tab. Copy and paste the following tags into the editor:
<?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_2_5.xsd" version="2.5"> </web-app>
- Add the content that you want the workbench to incorporate into the web.xml file that it generates for the WAR file for your Web service. You can add content in any of the tags that the schema for the Java Servlet 2.5 Specification defines.
Here is an example template:
<?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_2_5.xsd" version="2.5"> <filter> <filter-name>DebugFilter-In</filter-name> <description>Print XMl request, XML response and current timestamps</description> <filter-class>com.vzb.varwebservices.filter.DebugFilter</filter-class> <init-param> <param-name>input</param-name> <param-value>true</param-value> </init-param> </filter> <servlet> <servlet-name>testServlet1</servlet-name> <servlet-class>com.ibm.datatools.dsws.rt.testclient.testServlet1</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>testServlet1</servlet-name> <url-pattern>/TestClient/testServlet1</url-pattern> </servlet-mapping> <servlet> <servlet-name>testServlet2</servlet-name> <servlet-class>com.ibm.datatools.dsws.rt.testclient.testServlet2</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>testServlet2</servlet-name> <url-pattern>/TestClient/testServlet2</url-pattern> </servlet-mapping> </web-app>
- Save your template. The next time that you build your project, the workbench inserts the content of the template file into the web.xml file that goes into the newly generated WAR file.