maven 完整版打包

所有项目都依赖这个父项目

父项目

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.lhy.maven_parent</groupId>
	<artifactId>maven_parent</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<name>maven_parent</name>
	<properties>
		<project.version>0.0.1-SNAPSHOT</project.version>
	</properties>
	<modules>
		<module>ecache_test</module>
		<module>redis_test</module>
	</modules>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.lhy.maven_parent</groupId>
				<artifactId>ecache_test</artifactId>
				<version>${project.version}</version>
			</dependency>
			<dependency>
				<groupId>com.lhy.maven_parent</groupId>
				<artifactId>ecache_test</artifactId>
				<version>${project.version}</version>
				<type>war</type>
			</dependency>
			<dependency>
				<groupId>com.lhy.maven_parent</groupId>
				<artifactId>redis_test</artifactId>
				<version>${project.version}</version>
			</dependency>
			<dependency>
				<groupId>com.lhy.maven_parent</groupId>
				<artifactId>redis_test</artifactId>
				<version>${project.version}</version>
				<type>war</type>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<build>
	<pluginManagement>
		<plugins>
		<plugin>
		<!-- 去除运行时的maven错误 maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e. -->
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>org.apache.maven.plugins</groupId>
										<artifactId>maven-dependency-plugin</artifactId>
										<versionRange>[2.0,)</versionRange>
										<goals>
											<goal>copy-dependencies</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<ignore />
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			<plugin>
				<!-- classifier元素用来帮助定义构件输出的一些附属构件。附属构件与主构件对应,比如主构件是 kimi-app-2.0.0.jar 
					该项目可能还会通过使用一些插件生成 如 kimi-app-2.0.0-javadoc.jar 、 kimi-app-2.0.0-sources.jar 
					这样两个附属构件。 这时候,javadoc,sources就是这两个附属构件的classifier,这样附属构件也就拥有了自己唯一的坐标。 -->

				<!-- Maven的生命周期是抽象的,实际需要插件来完成任务,这一过程是通过将插件的目标(goal)绑定到生命周期的具体阶段(phase)来完成的。 
					如:将maven-compiler-plugin插件的compile目标绑定到default生命周期的compile阶段,完成项目的源代码编译: -->
				<artifactId>maven-jar-plugin</artifactId>
				<executions>
					<execution>
						<id>default-jar</id>
						<goals>
							<goal>jar</goal>
						</goals><!-- 打包的后缀 -->
						<phase>prepare-package</phase><!-- life的多个阶段 ,预打包 -->
						<configuration>
							<includes><!-- 引入 路径 -->
								<include>**/model/**</include>
							</includes>
						</configuration>
					</execution>
					<execution>
						<id>impl</id>
						<goals>
							<goal>jar</goal>
						</goals>
						<phase>prepare-package</phase>
						<configuration>
							<classifier>impl</classifier><!-- ***-impl.jar -->
							<excludes><!-- 排除 -->
								<exclude>**/model/**</exclude>
							</excludes>
							<includes><!-- 引入 -->
								<include>**/impl/**</include>
							</includes>
						</configuration>
					</execution>
					<execution>
						<id>web</id>
						<goals>
							<goal>jar</goal>
						</goals>
						<phase>prepare-package</phase>
						<configuration>
							<classifier>web</classifier>
							<includes>
								<include>**/web/**</include>
							</includes>
							<excludes>
								<exclude>**/model/**</exclude>
							</excludes>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<!-- 拷贝源文件 -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>unpack-dependencies</id> <!-- 拷贝并解压到相应目录 -->
						<phase>package</phase>
						<goals>
							<goal>unpack-dependencies</goal>
						</goals>
						<configuration>
							<includeTypes>war</includeTypes><!-- 导入文件类型 -->
							<excludeTransitive>true</excludeTransitive>
							<overWriteSnapshots>true</overWriteSnapshots>
							<type>war</type>
							<outputDirectory>  <!-- 解压 -->
								${project.build.directory}/${project.artifactId}.war
							</outputDirectory>
						</configuration>
					</execution>
					<execution>
						<id>copy-dependencies</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<includeTypes>jar</includeTypes>
							<overWriteSnapshots>true</overWriteSnapshots>
							<excludeGroupIds>org.eclipse.jetty,org.eclipse.jetty.orbit</excludeGroupIds>
							<excludeArtifactIds>jetty-schemas,javax.servlet-api,javax.servlet.jsp,javax.servlet.jsp-api,javax.servlet.jsp.jstl,javax.el</excludeArtifactIds>
							<type>jar</type>
							<excludeScope>provided</excludeScope>
							<outputDirectory>${project.build.directory}/${project.artifactId}.war/WEB-INF/lib</outputDirectory>
						</configuration>
					</execution>

				</executions>
			</plugin>
			<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-antrun-plugin</artifactId>
					<executions>
						<execution>
							<id>package</id>
							<phase>package</phase>
							<goals>
								<goal>run</goal>
							</goals>
							<configuration>
								<tasks>
									<copy todir="${project.build.directory}/${project.artifactId}.war/WEB-INF/classes" overwrite="true">
										<fileset dir="src/main/resources" includes="*.properties,*.xml,**/*.*"/>
									</copy>
									<copy todir="${project.build.directory}/${project.artifactId}.war" overwrite="true">
										<fileset dir="src/main/webapp" />
									</copy>
									<copy todir="${project.build.directory}/${project.artifactId}.war/WEB-INF/lib">
										<fileset  dir="${project.build.directory}" includes="*.jar"/>
									</copy>
									<zip
										destfile="${project.build.directory}/${project.artifactId}-${project.version}-war.zip">
										<zipfileset dir="${project.build.directory}/${project.artifactId}.war"
											 />
									</zip>
									<copy
										file="${project.build.directory}/${project.artifactId}-${project.version}-war.zip"
										tofile="${project.build.directory}/${project.artifactId}-${project.version}.war" />
									<delete file="${project.build.directory}/${project.artifactId}-${project.version}-war.zip"/>
									<delete dir="${project.build.directory}/${project.artifactId}.war"/>
								</tasks>
							</configuration>
						</execution>
					</executions>
				</plugin>
			<plugin>
					<groupId>org.codehaus.mojo</groupId>
					<artifactId>build-helper-maven-plugin</artifactId>
					<executions>
						<execution>
							<id>attach-artifacts</id>
							<phase>package</phase>
							<goals>
								<goal>attach-artifact</goal>
							</goals>
							<configuration>
								<artifacts>
									<artifact>
										<file>${project.build.directory}/${project.artifactId}-${project.version}.war</file>
										<type>war</type>
									</artifact>
								</artifacts>
							</configuration>
						</execution>
					</executions>
				</plugin>
		</plugins>
	</pluginManagement>
</build>

</project>

子项目


<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.lhy.maven_parent</groupId>
    <artifactId>maven_parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>redis_test</artifactId>
  <dependencies>
    
  </dependencies>
  <build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
			</plugin>
			<!-- 拷贝jar.war到lib目录,并删除源文件 -->
			 <plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
			</plugin>
    </plugins>
  </build>
</project>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值