war项目分别打成JAR和WAR,并被其他项目依赖
2017-03-01 18:36
393 查看
参考:http://blog.csdn.net/kobejayandy/article/details/8143925
http://www.tuicool.com/articles/eMJNza
<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>
-->
<dependency>
<groupId>c
e70d
om.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>
<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>
http://www.tuicool.com/articles/eMJNza
<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>c
e70d
om.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>
相关文章推荐
- Maven中如何配置WAR依赖WAR和JAR的多模块项目结构
- Maven中如何配置WAR依赖WAR和JAR的多模块项目结构
- maven配置: 生成war的同时生成jar, 并在其他artifact配置依赖于这个jar
- Maven 父子项目 聚合与继承 生命周期 打包插件 依赖打包 jar pom war
- Maven中如何配置WAR依赖WAR和JAR的多模块项目结构
- maven 父子项目 聚合与继承 生命周期 打包插件 依赖打包 jar pom war
- Maven项目中依赖其他工程(打成war包)
- maven 父子项目 聚合与继承 生命周期 打包插件 依赖打包 jar pom war
- 配置pom同时生成war包用来发布,生成jar包供其他war包依赖
- maven配置: 生成war的同时生成jar, 并在其他artifact配置依赖于这个jar
- android中以项目依赖的方式引用其他项目
- maven项目中添加对本地jdk tools.jar 的依赖
- eclipse编译android项目时,如何把依赖的jar包也打进apk中
- 利用maven将项目依赖的jar提取到指定文件夹
- Ear、Jar、War文件之间有何不同?它们分别使用在哪种环境下?
- Android 项目依赖导入jar引起的Jar mismatch! Fix your dependencies
- JBoss 7 里一个EJB依赖其他jar的几种方式
- 怎样解决maven项目中依赖的jar包和tomcat中的jar包的冲突
- 使用Maven管理依赖JAR文件,自定义项目布局,利用ANT生成不同的发布包
- Maven项目中如何同时Install成JAR和WAR包