Eclipse – Packaging a WAR file in an EAR so that WAR dependencies are available

eareclipsepackagingwarweblogic

I am adding a WAR module [my-web-app] to an existing EAR application [my-ear-app] that currently contains EJB modules only. The WAR module is a RESTful app written in Spring MVC 3.0.
The apps are maven 2.x apps.
When I run the EAR app on WebLogic 10.3.2 it fails to publish the WAR module that I added.
I am running this in WebLogic 10.3.2 from Eclipse Helios.
I have tried the app fuse warpath config in the pom but that didn't work. I also looked at the skinny wars approach. I added links to this relevant material at end of the post.

I can't seem to get past the missing oxm lib error – NoClassDefFoundError:org/springframework/oxm/Marshaller.

The error happens when an attempt is made to publish the EAR app to the WL app server.

The published EAR deploys as:

  • META-INF\application.xml
  • META-INF\MANIFEST.MF
  • META-INF\weblogic-application.xml
  • my-web-app.war
  • .beabuild.txt

The published WAR module from the EAR extracts as:

  • WEB-INF\lib\jstl-1.2.jar
  • WEB-INF\lib\spring-webmvc-3.0.5.RELEASE.jar

For comparison, the maven packaged WAR from the web app extracts as:

  • META-INF\MANIFEST.MF
  • WEB-INF\classes
  • WEB-INF\jsp
  • WEB-INF\lib (has all WAR dependencies)
  • WEB-INF\spring
  • web.xml

This is a partial error trace:

java.lang.Exception: Exception received from deployment driver. See Error Log view for more detail.
    at oracle.eclipse.tools.weblogic.server.internal.WlsJ2EEDeploymentHelper$DeploymentProgressListener.watch(WlsJ2EEDeploymentHelper.java:1559)
    at oracle.eclipse.tools.weblogic.server.internal.WlsJ2EEDeploymentHelper.deploy (WlsJ2EEDeploymentHelper.java:484)
    at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publishWeblogicModules (WeblogicServerBehaviour.java:1419)
    at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publishToServer    (WeblogicServerBehaviour.java:861)
    at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publishOnce (WeblogicServerBehaviour.java:655)
    at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publish (WeblogicServerBehaviour.java:522)
    at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish (ServerBehaviourDelegate.java:775)
    at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:2888)
    at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:337)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) Caused by: weblogic.application.ModuleException: [HTTP:101216]Servlet: "mywebapp" failed to preload on startup in Web application: "mywebapp". java.lang.NoClassDefFoundError: org/springframework/oxm/Marshaller
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:389)
        at java.lang.Class.getDeclaredConstructors(Class.java:1836)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determinCCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:227)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:930)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInsance (AbstractAutowireCapableBeanFactory.java:903)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject (AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactor.java:288)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java:580)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:425)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext (FrameworkServlet.java:442)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext (FrameworkServlet.java:458)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext (FrameworkServlet.java:339)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean (FrameworkServlet.java:306)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
        at javax.servlet.GenericServlet.init(GenericServlet.java:241)
        at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run (StubSecurityHelper.java:283)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
        at weblogic.servlet.internal.StubSecurityHelper.createServlet (StubSecurityHelper.java:64)
        at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance (StubLifecycleHelper.java:58)
        at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:48)
        at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:531)
        at weblogic.servlet.internal.WebAppServletContext.preloadServlet (WebAppServletContext.java:1915)
        at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup (WebAppServletContext.java:1889)
        at weblogic.servlet.internal.WebAppServletContext.preloadResources (WebAppServletContext.java:1807)
        at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3045)
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1397)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:460)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next (ModuleStateDriver.java:425)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
        at weblogic.application.internal.flow.ModuleStateDriver.start (ModuleStateDriver.java:119)
        at weblogic.application.internal.flow.ScopedModuleDriver.start (ScopedModuleDriver.java:200)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start (ModuleListenerInvoker.java:247)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next (ModuleStateDriver.java:425)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
        at weblogic.application.internal.flow.ModuleStateDriver.start (ModuleStateDriver.java:119)
        at weblogic.application.internal.flow.StartModulesFlow.activate (StartModulesFlow.java:27)
        at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:1267)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
        at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:409)
        at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:54)
... 

Below is the WAR module's org.eclipse.wst.common.component file, it has two EJB dependencies:

<?xml version="1.0" encoding="UTF-8"?> <project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="my-web-app">       
    <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
    <dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/ejb-module-1/ejb-module1">
        <dependency-type>uses</dependency-type>
    </dependent-module>
    <dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/ejb-module-2/ejb-module2">
        <dependency-type>uses</dependency-type>
    </dependent-module>
<property name="java-output-path" value="/my-web-app/target/classes"/>
    <property name="context-root" value="my-web-app"/>
</wb-module>

Below is the EAR module's org.eclipse.wst.common.component file. The EAR module has the web module dependency as well as many EJB dependencies. The EAR org.eclipse.wst.common.component file shows only two EJB dependencies to make it easier to read. The first EJB dependency type is EJB modules at the project root level and the second EJB dependency type is EJB modules written to the lib/ folder.

<?xml version="1.0" encoding="UTF-8"?>
    <project-modules id="moduleCoreId" project-version="1.5.0"> 
        <wb-module deploy-name="my-ejb-module"> 
            <wb-resource deploy-path="/" source-path="/EarContent"/> 
            <dependent-module archiveName="ejb-module-A.jar" deploy-path="/"   handle="module:/resource/ejbmoduleA/ejbmoduleA"> 
                <dependent-object/> 
                <dependency-type>uses</dependency-type> 
            </dependent-module> 
            <dependent-module archiveName="ejb-module-B-SNAPSHOT.jar" deploy-path="/lib" handle="module:/resource/ejb-module-B-SNAPSHOT/ejb-module-B-SNAPSHOT">
                <dependent-object/> 
                <dependency-type>uses</dependency-type> 
             </dependent-module> 
            <dependent-module archiveName="my-web-app.war" deploy-path="/" handle="module:/resource/my-web-app/my-web-app"> 
                <dependent-object/> 
                <dependency-type>uses</dependency-type>
             </dependent-module> 
     </wb-module>

Below is the pom.xml file for the EAR app:

<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/maven-v4_0_0.xsd">   

<modelVersion>4.0.0</modelVersion>
<groupId>com.ear.app</groupId>
<artifactId>my-ear-app</artifactId> 
<packaging>ear</packaging>
<version>1.0.0</version>

</properties>
    <spring.version>3.0.5.RELEASE</spring.version>
    <slf4j.version>1.6.1</slf4j.version>
</properties>

<dependencies>
    <dependency>        
        <groupId>com.ejb.module</groupId>
        <artifactId>ejb-module-W</artifactId>
        <version>1.0.0</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>com.ejb.module</groupId>
        <artifactId>ejb-module-X</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>ejb</type>
    </dependency>
    <dependency>        
        <groupId>com.ejb.module</groupId>
        <artifactId>ejb-module-Y</artifactId>
        <version>1.0.0</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>com.ejb.module</groupId>
        <artifactId>ejb-module-Z</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>ejb</type>
    </dependency>
    <dependency>
            <groupId>com.web.app</groupId>
            <artifactId>my-web-app</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>war</type>
    </dependency>
</dependencies> 
<build>
    <plugins>       
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.4</version>
            <configuration>
            <generateApplicationXml>false</generateApplicationXml>
                <earSourceDirectory>${basedir}/src/main/application</earSourceDirectory>
                <earSourceIncludes>META-INF/**</earSourceIncludes>
                <defaultJavaBundleDir>APP-INF/lib</defaultJavaBundleDir>
                <version>5</version>
                <modules>                                           <jarModule> 
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <includeInApplicationXml>false</includeInApplicationXml>                    
                    </jarModule>    
                    <jarModule>             
                        <groupId>com.ejb.module</groupId>
                        <artifactId>ejb-module-M</artifactId>                           
                        <includeInApplicationXml>false</includeInApplicationXml>                        
                    </jarModule>            
                    <jarModule>             
                        <groupId>com.ejb.module</groupId>
                        <artifactId>ejb-module-N</artifactId>                           
                        <includeInApplicationXml>false</includeInApplicationXml>                        
                    </jarModule>            
                    <jarModule>             
                        <groupId>com.ejb.module</groupId>
                        <artifactId>ejb-module-O</artifactId>                           
                        <includeInApplicationXml>false</includeInApplicationXml>                        
                    </jarModule>
                    <jarModule>             
                        <groupId>com.ejb.module</groupId>
                        <artifactId>ejb-module-P</artifactId>                               
                        <includeInApplicationXml>false</includeInApplicationXml>
                    </jarModule>
                    <jarModule>             
                        <groupId>org.codehaus.castor</groupId>
                        <artifactId>castor-core</artifactId>                
                        <includeInApplicationXml>false</includeInApplicationXml>                        
                    </jarModule>
                    <jarModule>             
                        <groupId>org.codehaus.castor</groupId>
                        <artifactId>castor-xml</artifactId>             
                        <includeInApplicationXml>false</includeInApplicationXml>                        
                    </jarModule>
                    <jarModule>             
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>        
                        <includeInApplicationXml>false</includeInApplicationXml>                        
                    </jarModule>            
                </modules>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>  
    <finalName>MY EAR APP</finalName>
</build>

This is the web module's pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.web.app</groupId>
<artifactId>my-web-app</artifactId>
<version>1.0.0-SNAPSHOT</version>   
<packaging>war</packaging>

</properties>
    <spring.version>3.0.5.RELEASE</spring.version>
    <slf4j.version>1.6.1</slf4j.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${slf4j.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>com.ejb.module</groupId>
        <artifactId>ejb-module-1</artifactId>
        <version>1.3.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.ejb.module</groupId>
        <artifactId>ejb-module-2</artifactId>
        <version>1.3.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
         <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

References:

  1. http://docs.codehaus.org/display/MAVENUSER/Solving+the+Skinny+Wars+problem
  2. Maven WAR dependency
    This one is similar to my problem and I attempted to use it to solve my issue but to no avail. It has an example of using warpath from appfuse.

Best Answer

I think org.springframework.oxm.Marshaller is not part of spring-webmvc-3.0.5.RELEASE.jar. I'm not familiar with webmvc or its dependencies, but perhaps spring-oxm-x.y.z.jar is one of its deps and thus needs to be included in WEB-INF/lib?

Regards,
 DagR.

Related Topic