eclipse 在 EAR 中打包 WAR 文件,以便 WAR 依赖项可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5193009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:54:49  来源:igfitidea点击:

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

eclipseweblogicpackagingwarear

提问by striker77

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.

我正在将 WAR 模块 [my-web-app] 添加到当前仅包含 EJB 模块的现有 EAR 应用程序 [my-ear-app]。WAR 模块是一个用 Spring MVC 3.0 编写的 RESTful 应用程序。
这些应用程序是 maven 2.x 应用程序。当我在 WebLogic 10.3.2 上运行 EAR 应用程序时,它无法发布我添加的 WAR 模块。我正在 Eclipse Helios 的 WebLogic 10.3.2 中运行它。
我已经在 pom 中尝试了应用程序保险丝War路径配置,但没有奏效。我还研究了瘦身War方法。我在帖子末尾添加了指向此相关材料的链接。

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

我似乎无法克服丢失的 oxm lib 错误 - NoClassDefFoundError:org/springframework/oxm/Marshaller。

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

当尝试将 EAR 应用程序发布到 WL 应用程序服务器时会发生该错误。

The published EAR deploys as:

已发布的 EAR 部署为:

  • META-INF\application.xml
  • META-INF\MANIFEST.MF
  • META-INF\weblogic-application.xml
  • my-web-app.war
  • .beabuild.txt
  • META-INF\application.xml
  • 元信息\清单.MF
  • META-INF\weblogic-application.xml
  • my-web-app.war
  • .beabuild.txt

The published WAR module from the EAR extracts as:

来自 EAR 的已发布 WAR 模块提取为:

  • WEB-INF\lib\jstl-1.2.jar
  • WEB-INF\lib\spring-webmvc-3.0.5.RELEASE.jar
  • 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:

为了比较,maven 从 web 应用程序中打包的 WAR 提取为:

  • META-INF\MANIFEST.MF
  • WEB-INF\classes
  • WEB-INF\jsp
  • WEB-INF\lib (has all WAR dependencies)
  • WEB-INF\spring
  • web.xml
  • 元信息\清单.MF
  • WEB-INF\类
  • WEB-INF\jsp
  • WEB-INF\lib(具有所有 WAR 依赖项)
  • WEB-INF\spring
  • 网页.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.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.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.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.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:

下面是 WAR 模块的 org.eclipse.wst.common.component 文件,它有两个 EJB 依赖项:

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

下面是 EAR 模块的 org.eclipse.wst.common.component 文件。EAR 模块具有 Web 模块依赖项以及许多 EJB 依赖项。EAR org.eclipse.wst.common.component 文件只显示了两个 EJB 依赖项,以便于阅读。第一个 EJB 依赖类型是项目根级别的 EJB 模块,第二个 EJB 依赖类型是写入 lib/ 文件夹的 EJB 模块。

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

下面是 EAR 应用程序的 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/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:

这是 web 模块的 pom.xml 文件:

<?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 dependencyThis 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.
  1. http://docs.codehaus.org/display/MAVENUSER/Solving+the+Skinny+Wars+problem
  2. Maven WAR 依赖这个和我的问题类似,我试图用它来解决我的问题,但无济于事。它有一个使用 appfuse 中的 warpath 的示例。

采纳答案by DagR

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?

我认为 org.springframework.oxm.Marshaller 不是 spring-webmvc-3.0.5.RELEASE.jar 的一部分。我不熟悉 webmvc 或其依赖项,但也许 spring-oxm-xyzjar 是其 deps 之一,因此需要包含在 WEB-INF/lib 中?

Regards,
 DagR.

问候,
 DagR。