新手学习Maven子模块

此前对maven的认识不多,最近得知maven对jar包的依赖以及源码的管理非常方便,所以也就开始使用maven了。

不过此时对maven的使用也仅限于maven对jar包的管理,其它功能使用得比不多。

近两天听说maven有个一子模块的功能,可以把一个项目分成不同的子项目来处理,并行开发,觉得这个功能非常实用,所以也想学习一下。

我一共新建了3个项目testP、testC1和testC2

---- testP
    | -- pom.xml (packaging: pom)
    | -- testC2 
         | -- pom.xml (packaging: jar)
    | -- testC1
         | -- pom.xml (packaging: war)


testP的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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.lee.test</groupId>
	<artifactId>testP</artifactId>
	<packaging>pom</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>testP Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>testP</finalName>
	</build>
	<modules>
		<module>testC2</module>
		<module>testC1</module>
	</modules>
	<properties>
		<!-- project character encoding setting -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<!-- java source version -->
		<maven.compiler.source>1.6</maven.compiler.source>
		<!-- java class version -->
		<maven.compiler.target>1.6</maven.compiler.target>
	</properties>
</project>



testC1的pom.xml

<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.lee.test</groupId>
		<artifactId>testP</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<groupId>com.lee.test</groupId>
	<artifactId>testC1</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>testC2 Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>testC2</finalName>
	</build>
	<properties>
		<!-- project character encoding setting -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<!-- java source version -->
		<maven.compiler.source>1.6</maven.compiler.source>
		<!-- java class version -->
		<maven.compiler.target>1.6</maven.compiler.target>
	</properties>
</project>


testC2的pom.xml

<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.lee.test</groupId>
		<artifactId>testP</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<groupId>com.lee.test</groupId>
	<artifactId>testC2</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>
	<name>testC2 Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>testC2</finalName>
	</build>
	<properties>
		<!-- project character encoding setting -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<!-- java source version -->
		<maven.compiler.source>1.6</maven.compiler.source>
		<!-- java class version -->
		<maven.compiler.target>1.6</maven.compiler.target>
	</properties>
</project>



对于个人而言,有点代码洁癖,所以会觉得testP这个项目有点别扭。它目录下的pom.xml文件以及其packaging的值为pom也感到不解。

觉得应该可以直接在testC1目录下,即pom.xml的packaging值为war值的项目下引入其它子模块就够了。可是自己尝试修改过几次,pom.xml文件都会报错。


总而言之,maven子模块的框架算是依葫芦画瓢地弄出来了,但是对齐原理以及为何这样设计仍旧是知之甚少。还希望有懂的maven子项目的朋友多多发言,教教小弟,小弟不甚感激!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值