Oracle WebLogic server 12c + Apache-CXF JAX-WS + Packaging WAR as EAR

In this article, we will learn and understand issues while deploying JAX-WS based SOAP Web Service’s WAR packaging into Oracle WebLogic 12c server and their workaround

Note: Example demonstrated to create EAR package is based on the article Apache-CXF-top-down-approach. So for other examples, dependencies in pom.xml and application.xml & weblogic-application.xml needs to be modified accordingly

1. Issues :

Deploying JAX-WS service into WebLogic server as WAR package won’t work as expected, because WebLogic’s in-built JAX-WS API takes their precedence over packaged jars into the WAR file

To overcome the above issue, we need to package this WAR file into an EAR file and then deploy it into the Oracle WebLogic server as EAR package

2. Workaround :

Pre-requisite: WAR packaging is successfully built and installed in our local maven repository –> this will ensure we know maven co-ordinates to add this WAR as dependencies in EAR project

For this example, local maven co-ordinates is

<groupId>in.bench.resources</groupId>
		<artifactId>ApacheCXF-JAX-WS-Top-Down</artifactId>
		<version>0.0.1-SNAPSHOT</version>

3. EAR Packaging :

Steps to be followed to package WAR file into an EAR file

  • Create a java project (structure as shown below)1_ApacheCXF-JAX-WS-EAR-App_initial_structure_screenshot
  • Add below contents to pom.xml with WAR as dependency and also add their JAR dependencies

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>in.bench.resources</groupId>
	<artifactId>ApacheCXF-JAX-WS-EAR-App</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>ear</packaging>
	<name>ApacheCXF-JAX-WS-EAR-App</name>
	<dependencies> <!-- add WAR as dependency to this EAR packaging -->
		<dependency>
			<groupId>in.bench.resources</groupId>
			<artifactId>ApacheCXF-JAX-WS-Top-Down</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency> <!-- apache cxf jax-ws 3.0.2 -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
			<version>3.0.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http</artifactId>
			<version>3.0.2</version>
		</dependency> <!-- spring framework 4.1.0 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.1.0.RELEASE</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>
	<build> <!-- final ear name -->
		<finalName>ApacheCXF-JAX-WS-EAR-App</finalName> <!-- maven ear plugin -->
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-ear-plugin</artifactId>
				<version>2.9.1</version>
				<configuration>
					<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
					<skinnyWars>true</skinnyWars>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
  • This application.xml contains information about different types of modules like JAR or WAR as part of EAR packaging
  • For this example, we have got just one WAR module

application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
	<display-name>ApacheCXF-JAX-WS-EAR-App</display-name>
	<module>
		<web>
			<web-uri>ApacheCXF-JAX-WS-Top-Down-0.0.1-SNAPSHOT.war</web-uri>
			<context-root>/ApacheCXF-JAX-WS-Top-Down</context-root>
		</web>
	</module>
</application>
  • This weblogic-application.xml tells the Oracle Weblogic server container to use jar libraries packaged within this EAR application, overriding in-built weblogic’s JAR modules

weblogic-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application
	xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-application"
	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/javaee_5.xsd 
	http://www.bea.com/ns/weblogic/weblogic-application 
	http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd">
	<wls:application-param>
		<wls:param-name>webapp.encoding.default</wls:param-name>
		<wls:param-value>UTF-8</wls:param-value>
	</wls:application-param>
	<wls:prefer-application-packages>
		<wls:package-name>com.ctc.wstx.*</wls:package-name>
		<wls:package-name>javax.wsdl.*</wls:package-name>
		<wls:package-name>org.apache.cxf.*</wls:package-name> 
		<!-- <wls:package-name>javax.jws.*</wls:package-name> -->
	</wls:prefer-application-packages>
</wls:weblogic-application>
  • Package structure after “mvn install” (Eclipse package explorer view)
    2_ApacheCXF-JAX-WS-EAR-App_after_mvn_install_screenshot

Conclusion:

  • This article demonstrated a simple example on how to package WAR file into an EAR application, where we got just one WAR module to be packaged into an EAR
  • This can be expanded for a large enterprise application which could be possibly got more modules like JAR, WAR & EJB as part of our EAR application

Related Articles :

Happy Coding !!
Happy Learning !!

JAX-WS: Known Behavior or issues w.r.t Oracle WebLogic server
Apache CXF JAX-WS: SOAP based Web Service using Top-Down approach + Integrating with Spring & Hibernate ORM framework