Writing Ant Targets for Web Services on the Tomcat Web Server

See Also

When working with web services on the Tomcat Web Server, you are recommended to use the Java Web Services Developer Pack 1.6 (JWSDP 1.6). However, the JWSDP-compliant Tomcat Web Server is based on Tomcat Web Server 5.0.19. Therefore, if you want to use a version of the Tomcat Web Server that is higher than 5.0.19, you cannot use JWSDP 1.6. Instead, you need to write Ant targets in the IDE, as described below.

To prepare to use Ant targets to deploy a web service on the Tomcat Web Server:

  1. Copy all JAR files from $NB_HOME/ide/modules/ext/jaxrpc16 to $NB_HOME/enterprise/apache-tomcat-5.5.17/common/lib.
  2. Make sure that the GlassFish server is registered in the IDE.
  3. In the Services window (Ctrl-5), expand the Servers node, right-click the Tomcat Web Server node, and choose Start. Doing this creates the full_path_to_$NB_USER_DIR/5.0/apache-tomcat-5.5.17_base folder. In this folder, enable the Tomcat Web Server's auto deploy functionality by switching autoDeploy="false" to autoDeploy="true" in the conf/server.xml folder. Right-click the Tomcat Web Server node and choose restart so that the server can load your change.

To create the web service or client files:

  1. Create a web application project. Set the GlassFish server as your target server.
  2. Do one of the following:

To write Ant targets to deploy a web service on the Tomcat Web Server:

  1. Add the following target to the build.xml file and change full_path_to_$NB_USER_DIR to the full path, such as c:\.netbeans:
    <target name="-pre-init">
      <property name="j2ee.platform.wscompile.classpath" value="${libs.jaxrpc16.classpath}"/>
      <property name="tomcat.home" value="full_path_to_$NB_USER_DIR/5.0/apache-tomcat-5.5.17_base"/>
    </target>

    The apache-tomcat-5.5.17_base folder is created only once the Tomcat Web Server has been started.

  2. Add the following target to the build.xml file:
    <target name="run-deploy" depends="init,compile,compile-jsps,-do-compile-single-jsp,dist">
     <property name="raw.war.name" value="${dist.dir}/raw-${war.name}"/>
     <copy file="${dist.war}" tofile="${raw.war.name}"/>
     <delete file="${dist.war}"/>
     <taskdef name="wsdeploy" classname="com.sun.xml.rpc.tools.ant.Wsdeploy" classpath="${wscompile.classpath}"/>
     <wsdeploy
       inWarFile="${raw.war.name}"
       outWarFile="${dist.war}"
       fork="true"
       classpath="${wscompile.classpath}:${build.classes.dir.real}:${javac.classpath}"
       keep="true"
       verbose="true"
       source="1.1.2"/>
     <delete file="${raw.war.name}"/>
     <copy file="${dist.war}" todir="${tomcat.home}/webapps"/>
    </target>
  3. Add the following target to the build.xml file and change my-host to your environment's host name and change my-port-number to your environment's port number:
    <target name="run-display-browser" if="do.display.browser" depends="run-deploy">
       <nbbrowse url="http://my-host:my-port-number/${ant.project.name}/${client.urlPart}"/>
    </target>

    Create an XML document in the WEB-INF folder. Call the XML document jaxrpc-ri. Add this content to jaxrpc-ri.xml and change mypackage.mysubpackage.myclassSEI to the fully qualified name of the SEI class and mypackage.mysubpackage.myclassImpl to the fully qualified name of the implementation class:

    <?xml version="1.0" encoding="UTF-8"?>
    <webServices
        xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
        version="1.0"
        targetNamespaceBase="http://java.sun.com/xml/ns/jax-rpc/wsi/wsdl"
        typeNamespaceBase="http://java.sun.com/xml/ns/jax-rpc/wsi/types"
        urlPatternBase="/webservice">
        <endpoint
        name="MyTomcatWS"
        displayName="TomcatService"
        description="Tomcat Web Service endpoint"
        interface="mypackage.mysubpackage.myclassSEI"
        implementation="mypackage.mysubpackage.myclassImpl"/>
        <endpointMapping
        endpointName="MyTomcatWS"
        urlPattern="/MyTomcatWS"/>
    </webServices>

    Now right-click the project node, choose Properties, select the Run pane, and type MyTomcatWS in Relative URL.

To deploy a web service or web service client on the Tomcat Web Server:

  1. Right-click the project node, choose Properties, select the Run pane, and select the Tomcat Web Server from the Server drop-down list.
  2. Right-click the project node and choose Build Project.
  3. Do one of the following:
  4. If you are behind a corporate firwall, set the proxy host and port number.
  5. In the Projects window, right-click the project and choose Run Project.
The web service deploys and is displayed in the browser, using the host name and port number specified in the <run-display-browser> target.
See Also
About the Tomcat Web Server
Authenticating the Tomcat Web Server
Setting Up a Tomcat Database Connection Pool

Legal Notices