I recently had a lot of problems trying to deploy the JAX-WS Web service client on Weblogic 9.2. It turns out there is no simple guide on how to achieve this, so I decided to put together this short entry on the wiki, hoping that it might be useful to others.
First, Weblogic 9.2 does not support web services using JAX-WS at all. It comes with older versions of XML-related java libraries that are incompatible with the latest JAX-WS (similar problems occur with Axis2, only Axis1 works flawlessly with Weblogic 9.x, but it is a very old and unsupported library).
So, in order to make it work, hacking is required. Here's how I did it (note that we are using ant in our legacy corporate project, you should probably use maven, which should eliminate 50% of these steps below):
1. Download the latest JAX-WS distribution from https://jax-ws.dev.java.net/ (The exact version I received is JAXWS2.2-20091203. Mail)
2. Install JAX-WS jars with dependencies in a separate folder, such as lib / webservices.
3.Create a template in ant to reference these banks:
<?xml version="1.0"?> <patternset id="jaxws.classpath"> <include name="webservices/jsr173_api.jar" /> <include name="webservices/jsr181-api.jar" /> <include name="webservices/jaxb-api.jar" /> <include name="webservices/jaxb-impl.jar" /> <include name="webservices/jaxb-xjc.jar" /> <include name="webservices/jaxws-tools.jar" /> <include name="webservices/jaxws-rt.jar" /> <include name="webservices/jaxws-api.jar" /> <include name="webservices/policy.jar" /> <include name="webservices/woodstox.jar" /> <include name="webservices/streambuffer.jar" /> <include name="webservices/stax-ex.jar" /> <include name="webservices/saaj-api.jar" /> <include name="webservices/saaj-impl.jar" /> <include name="webservices/gmbal-api-only.jar" /> </patternset>
4. Include the template in your target related to WAR. It might look something like this:
<?xml version="1.0"?> <copy todir="${wardir.lib}" includeEmptyDirs="false" flatten="true"> <fileset dir="${libs}"> <patternset refid="jaxws.classpath"/> </fileset> </copy>
(and not the flatten = "true" parameter - this is important, since by default Weblogic 9.x is not smart enough to access banks located in a different lcoation than WEB-INF / lib inside your WAR file)
5. In the event of a collision, Weblogic uses its own banks by default. We want JAX-WS banks from our application instead. This is achieved by preparing the weblogic-application.xml file and placing it in the META-INF folder in the deplotyed EAR file. It should look like this:
<?xml version="1.0"?> <weblogic-application xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <prefer-application-packages> <package-name>javax.jws.*</package-name> <package-name>javax.xml.bind.*</package-name> <package-name>javax.xml.crypto.*</package-name> <package-name>javax.xml.registry.*</package-name> <package-name>javax.xml.rpc.*</package-name> <package-name>javax.xml.soap.*</package-name> <package-name>javax.xml.stream.*</package-name> <package-name>javax.xml.ws.*</package-name> <package-name>com.sun.xml.api.streaming.*</package-name> </prefer-application-packages> </weblogic-application>
6. Repeat to place this weblogic-application.xml file in your EAR! The ant target for this might look something like this:
<?xml version="1.0"?> <target name="build-ear" depends="war, manifest"> <delete dir="${dist}"/> <mkdir dir="${dist}"/> <jar destfile="${warfile}" basedir="${wardir}"/> <ear destfile="${earfile}" appxml="resources/${app.name}/application.xml"> <fileset dir="${dist}" includes="${app.name}.war"/> <metainf dir="resources/META-INF"/> </ear> </target>
7. You also need to say weblogic so that your WEB-INF classes are preferred by those in the distribution. You do this by putting the following lines in your WEB-INF / weblogic.xml file:
<?xml version="1.0"?> <container-descriptor> <prefer-web-inf-classes>true</prefer-web-inf-classes> </container-descriptor>
8. And what is this for weblogic related configuration. Now configure only the JAX-WS target. In the example below, we simply create the stubs and web service classes based on the locally deployed WSDL file and put them in a folder in your application:
<?xml version="1.0"?> <target name="generate-jaxws-client"> <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"> <classpath path="classpath.main"/> </taskdef> <wsimport destdir="${src}" package="acme.somewhere.in.your.package.tree.webservices." keep="true" wsdl="http://localhost:8088/mockWebService?WSDL"> </wsimport> </target>
Remember the keep = "true" parameter. Without it, wsimport generates classes and ... removes them, believe it or not!
For bullying a web service, I suggest using SOAPUI, an open source project. Very simple deployment, which is crucial for testing intergation of web services.
9. We are almost there. Finally, you need to write a Java class to test the web service, first try running it as a standalone application (or as part of your unit tests).
10. Then try to run the same code using Weblogic. It should work. It worked for me. After a few days of frustration. And yes, I know that I should have put 9 and 10 under the same brand, but the heading โ10 steps to deploy the JAX-WS web service under 9.2 web logic using antโ sounds a lot better.
Please edit this post and improve it if you find something inactive!