maven父项目与子项目

maven父子项目的依赖,可以通过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>hw.hlatform.secg</groupId>
	<artifactId>secg-parent</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>//告诉父模块,什么包也不用生成
	<modules>//父页面所包含的子项目
		<module>../secg-core</module>
		<module>../secg-utils</module>
		<module>../secg-service</module>
		<module>../secg-pubilcinc</module>
		<module>../secg-webservice</module>
		<module>../secg-web</module>
		<module>../IHos-Api</module>
	</modules>

	<url>http://maven.apache.org</url>

	<properties>//编译的时候所用的编码
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<distributionManagement>
		<snapshotRepository>//每次发布都会在服务器上留下新的版本
			<id>user-snapshots</id>
			<name>User Project SNAPSHOTS</name>
			<url>http://192.168.0.199:8081/nexus/content/repositories/MyUserReposSnapshots/</url>
		</snapshotRepository>

		<repository>//jar所在的仓库,优先到这里寻找,如果没有则取网上下载
			<id>user-releases</id>
			<name>User Project Release</name>
			<url>http://192.168.0.199:8081/nexus/content/repositories/MyUserReposRelease/</url>
		</repository>
	</distributionManagement>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>4.10</version>
				<scope>test</scope>
			</dependency>
			<dependency>//子项目打成的jar,所有子项目用的公共jar全部可以打包到这里
				<groupId>${project.groupId}</groupId>
				<artifactId>secg-core</artifactId>
				<version>${project.version}</version>
			</dependency>
			<dependency>
				<groupId>${project.groupId}</groupId>
				<artifactId>secg-utils</artifactId>
				<version>${project.version}</version>
			</dependency>
			<dependency>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
				<version>1.2.16</version>
			</dependency>
			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<version>5.1.18</version>
			</dependency>
			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-log4j12</artifactId>
				<version>1.6.4</version>
			</dependency>
			<dependency>
				<groupId>javassist</groupId>
				<artifactId>javassist</artifactId>
				<version>3.12.1.GA</version>
			</dependency>
			<dependency>
				<groupId>org.ow2.orchestra.eclipse.birt</groupId>
				<artifactId>org.ow2.orchestra.eclipse.birt.chart.engine</artifactId>
				<version>3.7.0</version>
			</dependency>
			<dependency>
				<groupId>maven</groupId>
				<artifactId>maven-abbot-plugin</artifactId>
				<version>1.1</version>
			</dependency>

			<dependency>
				<groupId>mockobjects</groupId>
				<artifactId>alt-jdk1.3</artifactId>
				<version>0.07</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-web</artifactId>
				<version>3.1.1.RELEASE</version>
			</dependency>
			<dependency>
				<groupId>commons-logging</groupId>
				<artifactId>commons-logging</artifactId>
				<version>1.1.1</version>
			</dependency>
			<!-- http://mvnrepository.com/artifact/org.springframework/spring-context -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-context</artifactId>
				<version>3.2.1.RELEASE</version>
			</dependency>
			<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
			<dependency>
				<groupId>org.hibernate</groupId>
				<artifactId>hibernate-core</artifactId>
				<version>4.2.1.Final</version>
			</dependency>
			<!-- http://mvnrepository.com/artifact/org.springframework/spring-orm -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-orm</artifactId>
				<version>3.2.1.RELEASE</version>
			</dependency>
			<!-- http://mvnrepository.com/artifact/org.springframework/spring-oxm -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-oxm</artifactId>
				<version>3.2.1.RELEASE</version>
			</dependency>

			<!-- http://mvnrepository.com/artifact/org.springframework/spring-test -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
				<version>3.2.1.RELEASE</version>
			</dependency>

			<!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>javax.servlet-api</artifactId>
				<version>3.1.0</version>
				<scope>provided</scope>
			</dependency>

		</dependencies>
	</dependencyManagement>
	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-source-plugin</artifactId>//打源码包
					<version>2.1.2</version>
					<executions>
						<execution>
							<phase>package</phase>
							<goals>
								<goal>jar-no-fork</goal>
							</goals>
						</execution>
					</executions>
				</plugin>

				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-rar-plugin</artifactId>//打rar包
					<version>2.2</version>
					<executions>
						<execution>
							<phase>package</phase>
							<goals>
								<goal>rar</goal>
							</goals>
						</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>hw.hlatform.secg</groupId>
		<artifactId>secg-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<relativePath>../secg-parent/pom.xml</relativePath>//指明父项目的pom.xml文件
	</parent>
	<artifactId>secg-core</artifactId>
	<packaging>jar</packaging>

	<name>secg-core</name>
	<url>http://maven.apache.org</url>

	<dependencies>
		<dependency>//父类所引用的jar,版本号与父类保持一致
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</dependency>
		<!-- http://mvnrepository.com/artifact/org.springframework/spring-context -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
		</dependency>
		<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
		</dependency>
		<!-- http://mvnrepository.com/artifact/org.springframework/spring-orm -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
		</dependency>
		<dependency>
			<groupId>hw.hlatform.secg</groupId>
			<artifactId>secg-utils</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>//打源码包
			</plugin>

		</plugins>
	</build>
</project>

猜你喜欢

转载自747017186.iteye.com/blog/2338081