Monday, November 9, 2009

Configure Tomcat 6 for JAX-WS

As a servlet container, Tomcat is not a full J2EE container hence requires some additional configuration in order to support JAX-WS. This article describes this configuration step-by-step:

  1. Download a copy of the JAX-WS library – Instructions here were tested this on version 2.1.5 (https://jax-ws.dev.java.net/2.1.5/)
  2. Copy the file JAXWS2.1.5-20081030.jar to an appropriate folder on your computer – say, /root/tools/ JAXWS2.1.5-20081030.jar
  3. Execute the jar: java –jar JAXWS2.1.5-20081030.jar
  4. This in effect unpacks the files contained in this jar. You should get a folder /root/tools/jaxws-ri containing the supporting libraries, docs, tools and samples. Let’s call this path $JAX-WS-HOME$.
  5. Copy the jar files in $JAX-WS-HOME$/lib/ to the Tomcat (let’s call the install path for this $CATALINA_HOME$) library$CATALINA_HOME$/lib and $CATALINA_HOME$/shared/lib path.
  6. Create an folder in the Tomcat installation directory called “endorsed”. The full path should be$CATALINA_HOME$/endorsed.
  7. Copy the files “jaxb-api.jar” and “jaxws-api.jar” from the “$JAX_WS_HOME$/lib” to the “$CATALINA_HOME$/endorsed/”folder.
  8. Edit the Tomcat configuration file “$CATALINA_HOME$/conf/catalina.properties” (You might want to take a backup before you edit it). There should be a property with the key “shared.loader”. Make sure the path $CATALINA_HOME$/shared/lib/*.jar is included in the comma separated list of paths in the value for this property. For example it could look like :shared.loader=/etc/tomcat/shared/lib/*.jar. That’s the main set of configuration that needs to be done.
  9. Before running tomcat, ensure the following property is to be set on the script used to start tomcat:
    -Djava.endorsed.dirs=$CATALINA_HOME$\endorsed
  10. This ensures the two jars we copied into the endorsed folder are picked up.
  11. Start tomcat.
UPDATE: This post makes assumptions about your source and web-archive being correctly set up. When I was doing this, I was working in a Contract-First approach and I wrote a quick guide to that here. This covers how your web.xml and sun-jaxws.xml file should be done. When I get sometime I'll upload a redacted version of my code as it has some work stuff. Good luck!

5 comments:

mivaas19 said...

what is the start script for running tomcat?

Trevor Kimenye said...

Its startup.bat (startup.sh for UNIX) in the bin directory

Tim said...

I know this is an old post, but do you know why TC keeps giving me a CCE on startup - [classname] cannot be cast to javax.servlet.Servlet? It's as if TC doesn't know this is a Webservice. I followed your instructions above and googled everywhere for answers but no avail.
Thanks.

Trevor Kimenye said...

Hi Tim,

Sorry about your woes with this. Have you checked out the following links:

http://kingsfleet.blogspot.com/2009/01/deploying-jax-ws-ri-to-tom-cat.html

AND

http://stackoverflow.com/questions/2511547/how-to-manually-deploy-a-web-service-on-tomcat-6/2534157#2534157

Its been a while, but my post made some assumptions about the source (I was working on a WSDL first basis but it shouldn't matter which approach you are taking). I'll update it with as much as I can redact from my work.

cialis said...

I, of course, a newcomer to this blog, but the author does not agree