war项目分别打成JAR和WAR,并被其他项目依赖

<1>被依赖的war项目分别打成JAR和war:

< plugin >
           < groupId >org.apache.maven.plugins </ groupId >
           < artifactId >maven-war-plugin </ artifactId >
           < version >2.4 </ version >
        </ plugin >
        < plugin >
                < groupId >org.apache.maven.plugins </ groupId >
                < artifactId >maven-jar-plugin </ artifactId >
                < version >2.3 </ version >
                < configuration >
                  < includes >
                 < include >com/** </ include >
              </ includes >
                </ configuration >
                < executions >
                    < execution >
                        < id >make-a-jar </ id >
                        < phase >package </ phase >
                        < goals >
                            < goal >jar </ goal >
                        </ goals >
                        < configuration >
                      < classifier >api </ classifier >
                     </ configuration >
                    </ execution >
                </ executions >
            </ plugin >

<2>引入jar和war包

<!-- 引入基础 war -->
      < dependency >
        < groupId >com.hnjz </ groupId >
        < artifactId >hnjz-web-basic </ artifactId >
        < version >${hnjz.basic.version} </ version >
        < type >war </ type >
      </ dependency >
      < dependency >
        < groupId >com.hnjz </ groupId >
        < artifactId >hnjz-web-basic </ artifactId >
        < version >${hnjz.basic.version} </ version >
        < type >jar </ type >
        < scope >compile </ scope >
        < classifier >api </ classifier >
      </ dependency >

<3>配置两个war包内容合并

< plugin >
           < groupId >org.apache.maven.plugins </ groupId >
           < artifactId >maven-war-plugin </ artifactId >
           < version >2.6 </ version >
           < configuration >
           <!-- 依赖的 war 项目,默认在 target/war/work 中,然后被打包进 war 文件 , 指定后为 target/work -->
           < workDirectory >${project.build.directory}/work </ workDirectory >
           <!-- 告诉 maven-war-plugin 另一个路径 "WebContent", 产生的结果就是 , 执行 mvn package ,war-plugin warpath-plugin 会将当前 war 和所有依赖的 war web 资源都拷贝到该 WebContent 目录下 . 这样 ,WebContent 目录包含的内容就是最终打包成 WAR 的内容了 ,如果不指定, 默认情况下是在 target 目录下生成一个 ,war 包解压后的文件夹 -->
              <!-- <webappDirectory>WebContent</webappDirectory> -->
              < useCache >false </ useCache >
              < archive >
                 < addMavenDescriptor >true </ addMavenDescriptor >
              </ archive >
              < overlays >
                 < overlay >
                    < groupId >com.hnjz </ groupId >
                    < artifactId >hnjz-web-basic </ artifactId >
                 </ overlay >
                 < overlay >
                    <!-- empty groupId/artifactId is detected as the current build -->
                    <!-- 代表当前 WAR 项目,默认情况当前 WAR 项目是先被拷贝,如果要控制其顺序,则使用空的 overlay -->
                    <!-- any other overlay will be applied after the current build since
                      they have not been configured in the overlays element -->
                 </ overlay >
              </ overlays >
              <!-- 排除依赖 war 包中的哪些文件
              <dependentWarExcludes>*/web.xml,WEB-INF/lib/*,/sql-map-config.xml,/jdbc.properties,/META-INF/*</dependentWarExcludes>
               -->
                < dependentWarExcludes >/META-INF/* </ dependentWarExcludes >
           </ configuration >
        </ plugin >
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值