1:属性的定义与使用
定义属性:
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <junit.version>4.10</junit.version> </properties>
使用属性:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency>
2:父pom声明与子pom引入父pom
父pom:
<groupId>org.pine.user</groupId> <artifactId>user-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging>
子pom引入父pom:
<parent> <groupId>org.pine.user</groupId> <artifactId>user-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <relativePath>../user-parent/pom.xml</relativePath> </parent>
3:依赖的管理与声明、子pom手动继承与引入依赖
<!-- <dependencies>中的依赖,子pom会自动继承与引入 --> <dependencies> </dependencies> <!-- <dependencyManagement>只是对依赖进行声明与管理,子pom不会自动继承与引入,需要手动继承与引入 --> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.pine.user</groupId> <artifactId>user-core</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.pine.user</groupId> <artifactId>user-log</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!-- jfreechart --> <dependency> <groupId>org.jfree</groupId> <artifactId>jfreechart</artifactId> <version>1.5.3</version> </dependency> </dependencies> </dependencyManagement> 子pom手动继承与引入依赖: <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>org.pine.user</groupId> <artifactId>user-dao</artifactId> </dependency> <dependency> <groupId>org.pine.user</groupId> <artifactId>user-log</artifactId> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> </dependencies>
4:将依赖的聚合整合到父pom中
<groupId>org.pine.user</groupId> <artifactId>user-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <!-- 依赖的聚合:将所有模块进行聚合,统一进行编译,测试,打包,安装操作 --> <!-- 将依赖的聚合整合到父pom中(将依赖的聚合整合到依赖的继承中) 这样user-parent既是做依赖的聚合,又是做依赖的继承 --> <modules> <module>../user-core</module> <module>../user-log</module> <module>../user-dao</module> <module>../user-service</module> </modules>