12.3.3 web.xmlを作成する

WARファイルの構成要素として必要なweb.xmlを作成します。

web.xmlの作成例を次に示します。

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

   <description>Sample web service &quot;tutorial&quot;</description>
   <display-name>Sample_web_service_jaxrs_tutorial</display-name>
   <servlet>
       <servlet-name>CosminexusJaxrsServlet</servlet-name>
       <servlet-class>
           com.cosminexus.jersey.spi.container.servlet.ServletContainer
       </servlet-class>
       <init-param>
           <param-name>com.sun.jersey.config.property.packages</param-name>
           <param-value>com.sample.resources;com.sample.providers</param-value>
       </init-param>
       <!-- POJO JSON support web.xml configuration -->
       <init-param>
           <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
           <param-value>true</param-value>
       </init-param>
   </servlet>
   <servlet-mapping>
       <servlet-name>CosminexusJaxrsServlet</servlet-name>
       <url-pattern>/*</url-pattern>
   </servlet-mapping>
</web-app>

バージョン2.5のweb.xmlを作成する場合は,web-app要素のversion属性を"2.5"に,xsd:schemaLocation属性の二つ目のロケーション情報を"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"にしてください。

作成したweb.xmlは,UTF-8形式でc:¥temp¥jaxrs¥works¥tutorial¥server¥WEB-INF¥ディレクトリに保存します。web.xmlの設定項目については,「3.4 web.xmlの作成」を参照してください。