X

Geertjan's Blog

  • September 15, 2005

Deploying JAX-RPC Web Services to Tomcat

Geertjan Wielenga
Product Manager
To deploy a web service in NetBeans IDE 5.0 to Tomcat:

  1. Copy all JAR files from $NB_HOME/ide6/ext/jaxrpc16 to:
    • $NB_HOME\\enterprise2\\jakarta-tomcat-5.5.7\\common\\lib
    • $NB_HOME\\enterprise2\\jakarta-tomcat-5.5.7\\server\\lib
    • $NB_HOME\\enterprise2\\jakarta-tomcat-5.5.7\\shared\\lib

    Of course, only one of the above is needed, but since I don't know for sure which one, I copied the JAR files to all the lib folders I could find in $NB_HOME\\enterprise2\\jakarta-tomcat-5.5.7.

    Note: If you are going to deploy to the bundled Tomcat, see issue 59943 and take the specified steps.

  2. Create web application (Ctrl-Shift-N). In the Project Properties dialog box, set Tomcat as your target server and add JAX-RPC 1.6 to your compile-time libraries. (Not 100% sure whether the latter part is correct, since the -pre-init target below enables the web service to be compiled.)

  3. Add these targets to your build.xml:
    <target name="-pre-init">
    <property name="j2ee.platform.wscompile.classpath" value="${libs.jaxrpc16.classpath}"/>
    <property name="tomcat.home" value="full_path_to_$NB_HOME\\enterprise2\\jakarta-tomcat-5.5.7"/>
    </target>

    Make sure to set the value applicable to your environment for tomcat.home in the target above.

    <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>
    <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>

    Make sure to set the value applicable to your environment for my-host and my-port-number in the target above.

  4. Create an XML file in WEB-INF. Call it jaxrpc-ri.xml with this content:
    <?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>

    Make sure to set the value applicable to your environment for interface and implementation in the target above.

    Take the url-pattern from the file above (here it is MyTomcatWS) and put it in the project's Relative URL edit box (in the Run Panel, in the Project Properties dialog box).

  5. Use Web Service wizard to create the web service files and then develop them further. I found later that I had to delete the existing servlet mappings that the IDE created in the web.xml for the web service. If I didn't do this, there was some kind of conflict with Tomcat and deployment didn't work because Tomcat didn't recognize the web service as a servlet.

  6. Build the web service.

  7. Start the server. (The server will not start automatically. In the Runtime window, start the server manually.)

  8. Run the project. I found that it didn't work, then I stopped the bundled server, restarted it, checked the Output window to see whether Tomcat correctly deployed the application (and then I discovered what I described above in step 5), right-clicked the application's node in the Runtime window (within 'Web Applications' under Tomcat's server node) to open it in a browser, and then I manually typed in the url-pattern specified in the jaxrpc-ri.xml file. Then, the world made sense again and I saw the following (click to enlarge both screenshots):




The process above may seem complicated, but many of its steps are due to my own ignorance -- there's a lot of overkill in these steps and as soon as I find out which parts are unnecessary, I'll blog about it and prune where necessary. Thanks to Lukas -- he's the first person (maybe in the whole world) to have developed and deployed a JAX-RPC web service from NetBeans to Tomcat. It's really very cool that this is at all possible, since Tomcat isn't a J2EE 1.4 server (i.e., it's not an application server, but a web server).

Join the discussion

Comments ( 3 )
  • niha Friday, May 25, 2007
    what are you mean by this?
  • Martin Dodd Sunday, August 16, 2009

    I need someone to help. Currently I am trying to deploy a JAX-WS Style Web service client to hosted web site. Everytime I run it I keep getting Error 500 when I call the client using soap when deployd to a hosted site. This works fine for the local deployed scenario, but on deploying to hosted server the problem occurs. Is there configuration change I need to make, or the way I do the deployment to the hosted server. Currently I am uploading the war file directly from the local location to the hosted site. See URL for details of the problem:

    http://forums.sun.com/thread.jspa?messageID=10793121&#10793121

    My configuration is: Netbeans 6.5.1, TomCat 6.0.18, jdk 6.0.14.

    If you have any suggestions, I would appreciate your help.


  • bern Thursday, January 7, 2010

    Hi, people, i need someone to help me.The problem is how to execute a web service in one aplication without calling it from another aplication. I created a single web service in netbean 6.8 version, I can invocate it from c#.net and it runs fine, but i don´t know the way to do that by using java. Please if someone knows that, write me back. thanks in advance...this is my email fuloplo@hotmail.com.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.