【问题标题】:Maven skinny war with warpathMaven与warpath的瘦身战争
【发布时间】:2012-07-11 06:46:11
【问题描述】:

我有一个项目,其中 3 个战争模块被打包在一个耳模块中。我的问题是每个库 jar 都包含在每个 war-modules 以及 ear-module 中,这使得生成的 ear-file 非常大(目前大约 190MB)。

我在这里按照使用 maven 进行瘦身战争的教程进行操作:http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html

有了这个,我设法将耳朵的大小缩小到 45MB 左右,这很好,但是当我尝试部署到 glassfish 时,它抱怨缺少一些类。

我发现这是由于对 appfuse-struts 的依赖,它被打包为一个 war 文件。这包括在其中一个战争项目中使用战争路径依赖。

由于制作瘦战争的教程指出,战争中发现的所有依赖项也必须在耳朵中定义。我试过这个,但是 appfuse-struts 依赖是一个战争路径,这使它不起作用。 (当只向ear pom添加war依赖时,它抱怨它没有找到一些类,并且当添加warpath依赖时maven抱怨它不知道warpath是什么。)

当战争使用战争路径依赖时,有没有人知道用瘦战争创建耳朵的方法?

【问题讨论】:

    标签: maven war ear appfuse skinny-war


    【解决方案1】:

    我想我可能已经找到了解决方案:

    在skinny wars 教程中,应该将WEB-INF/lib/*.jar 添加到packagingExcludes。然后,将所有依赖项添加到 ear-configuration 中,使其可用于 jar。

    问题是war打包的依赖不会将其传递依赖添加到ear的lib文件夹中,所以它们要么需要找到进入ear lib文件夹的方式,要么是WEB-INF/lib文件夹战争包。

    我选择使用最后一个,将它们添加到 war-file 的 WEB-INF/lib 中。

    为此,首先通过mvn dependency:tree 获取包含war/warpath 资源的war 项目的依赖树。

    接下来,找到 warpath 依赖项。就我而言,它看起来像这样:

          +- org.appfuse:appfuse-struts:warpath:2.0.2:compile
          |  +- org.appfuse:appfuse-web-common:war:2.0.2:compile
          |  +- org.appfuse:appfuse-web-common:warpath:2.0.2:compile
          |  +- displaytag:displaytag:jar:1.1.1:compile
          |  |  \- org.slf4j:jcl104-over-slf4j:jar:1.4.2:compile
          |  +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
          |  +- org.apache.commons:commons-io:jar:1.3.2:compile
          |  +- org.appfuse:appfuse-service:jar:2.0.2:compile
          |  |  +- velocity:velocity:jar:1.4:compile
          |  |  |  \- velocity:velocity-dep:jar:1.4:runtime
          |  |  +- org.codehaus.xfire:xfire-java5:jar:1.2.6:compile
          |  |  |  +- org.codehaus.xfire:xfire-aegis:jar:1.2.6:compile
          |  |  |  |  \- net.java.dev.stax-utils:stax-utils:jar:20040917:compile
          |  |  |  +- org.codehaus.xfire:xfire-annotations:jar:1.2.6:compile
          |  |  |  +- xfire:xfire-jsr181-api:jar:1.0-M1:compile
          |  |  |  \- org.codehaus.xfire:xfire-core:jar:1.2.6:compile
          |  |  |     +- stax:stax-api:jar:1.0.1:compile
          |  |  |     +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:compile
          |  |  |     \- commons-httpclient:commons-httpclient:jar:3.0:compile
          |  |  \- org.codehaus.xfire:xfire-spring:jar:1.2.6:compile
          |  |     +- org.apache.xbean:xbean-spring:jar:2.8:compile
          |  |     \- org.codehaus.xfire:xfire-xmlbeans:jar:1.2.6:compile
          |  |        \- xmlbeans:xbean:jar:2.2.0:compile
          |  +- commons-dbcp:commons-dbcp:jar:1.2.2:compile
          |  |  \- commons-pool:commons-pool:jar:1.3:compile
          |  +- org.directwebremoting:dwr:jar:2.0.1:compile
          |  +- javax.servlet:jstl:jar:1.1.2:compile
          |  +- taglibs:standard:jar:1.1.2:compile
          |  +- opensymphony:oscache:jar:2.3:compile
          |  +- opensymphony:sitemesh:jar:2.2.1:compile
          |  +- org.tuckey:urlrewritefilter:jar:3.0.4:compile
          |  \- commons-lang:commons-lang:jar:2.4:compile
    

    因此,我们需要确保这些可用。这可以通过将 WEB-INF/lib/* 的 packagingExclude 更改为不排除所有内容来完成,而是排除除我们想要保留的内容之外的所有内容。

    这可以通过这种方式完成:

          <packagingExcludes>
           %regex[WEB-INF/lib/(?!clickstream|struts|appfuse|commons-fileupload|commons-dbcp|dwr|oscache|sitemesh|urlrewritefilter|commons-lang|velocity|xwork|commons-digester).*.jar]
          </packagingExcludes>
    

    这将使 glassfish 不再抱怨找不到类。我还没有完全到那里,所以可能需要包括更多的罐子,但它越来越近了。

    【讨论】:

    • 我的完整包装Excludes-regex 使一切正常后看起来像这样:%regex[WEB-INF/lib/(?!clickstream|struts|appfuse|commons-fileupload|commons-dbcp|dwr|oscache |sitemesh|urlrewritefilter|commons-lang|velocity|xwork|commons-digester|xfire|xbean|ognl|freemarker|activemq).*.jar]
    猜你喜欢
    • 2014-05-10
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    相关资源
    最近更新 更多