maven中jar包和war包的继承

  最近项目中,有个主干版本,然后来了个新需求,在原有需求中升级,前提是原有需求还得继续使用,按以前的习惯方式是拉取分支代码版本作管理,然后做代码合并。这次考虑分支与主干版本的周期跨越太大,于是用到了maven的包继承,版本稳定后,去除旧的包。

1.jar包继承

现有两个模块:

com.isoftstone.hyom.pickingcode 这是原有模块包.
com.isoftstone.hyom.pickingcode 这是新加的模块包,pom.xml文件如下:

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.isoftstone.hyom</groupId>
		<artifactId>com.isoftstone.hyom</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>com.isoftstone.hyom.pickingcode_new</artifactId>
	<name>com.isoftstone.hyom.pickingcode_new</name>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>


		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>com.isoftstone.hyom.pickingcode</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>
	
	<build>
		<plugins>


			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>2.4.3</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<artifactSet>
								<includes>
									<include>com.isoftstone.hyom:com.isoftstone.hyom.pickingcode</include>
								</includes>
								<excludes>
									<exclude>*:*:jar</exclude>
								</excludes>
							</artifactSet>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project> 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.isoftstone.hyom</groupId>
		<artifactId>com.isoftstone.hyom</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>com.isoftstone.hyom.pickingcode_new</artifactId>
	<name>com.isoftstone.hyom.pickingcode_new</name>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>


		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>com.isoftstone.hyom.pickingcode</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>
	
	<build>
		<plugins>


			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>2.4.3</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<artifactSet>
								<includes>
									<include>com.isoftstone.hyom:com.isoftstone.hyom.pickingcode</include>
								</includes>
								<excludes>
									<exclude>*:*:jar</exclude>
								</excludes>
							</artifactSet>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project> 
 

2.war包继承

 

同理两个war包

uomp-lec 原有war包

uomp-lec-new 新建war包,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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.isoftstone.hyom</groupId>
		<artifactId>com.isoftstone.hyom.build.war</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>uomp-lec-new</artifactId>
	<packaging>war</packaging>
	
	<properties>
	<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
	</properties>


	<dependencies>
		<!-- 引入原有war包 -->
		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>uomp-lec</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency>
		
		<!-- 引入新的jar包 -->
		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>com.isoftstone.hyom.outeradmin_new</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>


		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>com.isoftstone.hyom.pickingcode_new</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>


	<build>
		<plugins>
		   <plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<compilerArguments>
						<endorseddirs>${endorsed.dir}</endorseddirs>
					</compilerArguments>
				</configuration>
			</plugin>
		   <!-- 排除原有jar包 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<failOnMissingWebXml>false</failOnMissingWebXml>
					<packagingExcludes>WEB-INF/lib/com.isoftstone.hyom.outeradmin-0.0.1-SNAPSHOT.jar,WEB-INF/lib/com.isoftstone.hyom.pickingcode-0.0.1-SNAPSHOT.jar</packagingExcludes>
				</configuration>
				<executions>
				</executions>
			</plugin>
			<!-- 排除原有jar包 -->
			<plugin>
				<groupId>org.eclipse.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>9.2.3.v20140905</version>
				<configuration>
					<packagingExcludes>WEB-INF/lib/com.isoftstone.hyom.outeradmin-0.0.1-SNAPSHOT.jar,WEB-INF/lib/com.isoftstone.hyom.pickingcode-0.0.1-SNAPSHOT.jar</packagingExcludes>
					<scanIntervalSeconds>10</scanIntervalSeconds>
					<reload>manual</reload>
					<webApp>
						<contextPath>/uomp-lec</contextPath>
					</webApp>
				</configuration>
			</plugin>


			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
			</plugin>
		</plugins>
		<finalName>uomp-lec</finalName>
	</build>
</project>
	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.isoftstone.hyom</groupId>
		<artifactId>com.isoftstone.hyom.build.war</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>uomp-lec-new</artifactId>
	<packaging>war</packaging>
	
	<properties>
	<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
	</properties>


	<dependencies>
		<!-- 引入原有war包 -->
		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>uomp-lec</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency>
		
		<!-- 引入新的jar包 -->
		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>com.isoftstone.hyom.outeradmin_new</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>


		<dependency>
			<groupId>com.isoftstone.hyom</groupId>
			<artifactId>com.isoftstone.hyom.pickingcode_new</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>


	<build>
		<plugins>
		   <plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<compilerArguments>
						<endorseddirs>${endorsed.dir}</endorseddirs>
					</compilerArguments>
				</configuration>
			</plugin>
		   <!-- 排除原有jar包 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<failOnMissingWebXml>false</failOnMissingWebXml>
					<packagingExcludes>WEB-INF/lib/com.isoftstone.hyom.outeradmin-0.0.1-SNAPSHOT.jar,WEB-INF/lib/com.isoftstone.hyom.pickingcode-0.0.1-SNAPSHOT.jar</packagingExcludes>
				</configuration>
				<executions>
				</executions>
			</plugin>
			<!-- 排除原有jar包 -->
			<plugin>
				<groupId>org.eclipse.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>9.2.3.v20140905</version>
				<configuration>
					<packagingExcludes>WEB-INF/lib/com.isoftstone.hyom.outeradmin-0.0.1-SNAPSHOT.jar,WEB-INF/lib/com.isoftstone.hyom.pickingcode-0.0.1-SNAPSHOT.jar</packagingExcludes>
					<scanIntervalSeconds>10</scanIntervalSeconds>
					<reload>manual</reload>
					<webApp>
						<contextPath>/uomp-lec</contextPath>
					</webApp>
				</configuration>
			</plugin>


			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
			</plugin>
		</plugins>
		<finalName>uomp-lec</finalName>
	</build>
</project>
 

 

3. 在新的模块包中,新建同包名况且同类名时,打包时,可以原有类。

 

上述源代码打包后,在新包中可以看到,继承了原本所有类,并且覆盖了,同包同类文件,如图:

于是我们就可以在这个新包里面进行开发,如果原本中哪个类需要变动,就在新包中建立同包,同类进行覆盖。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值