Maven Study Notes 2
2014-05-01 18:14
246 查看
1. <dependencyManagement>
<dependencyManagement> <dependencies> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.5</version> </dependency> </dependency> </dependencies> </dependencyManagement>通过该标签,可以在根 pom.xml 中统一依赖的版本。
然后,在各个子模块中只要关注 groupId 和 artifactId 就行了。
该标签不会引入实际依赖,但会对依赖做出约束。
2. 依赖范围
compile默认选项。
对编译,测试,运行三种 classpath 都有效。
provided
对编译,测试有效,运行无效。
典型的例子是 servlet-api,编译时需要依赖,运行时该架包有服务器提供。
runtime
编译时无效,运行、测试有效。
典型例子,jdbc。
3. 排除重复依赖
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.5.ga</version> <exclusions> <exclusion> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> </exclusion> </exclusions> </dependency> <dependency>
4. 一种实践方式
比如我们可以把持久层的东西放在一块:<project> <groupId>org.sonatype.mavenbook</groupId> <artifactId>persistence-deps</artifactId> <version>1.0</version> <packaging>pom</packaging> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>${hibernateVersion}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>${hibernateAnnotationsVersion}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-hibernate3</artifactId> <version>${springVersion}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysqlVersion}</version> </dependency> </dependencies> <properties> <mysqlVersion>(5.1,)</mysqlVersion> <springVersion>(2.0.6,)</springVersion> <hibernateVersion>3.2.5.ga</hibernateVersion> <hibernateAnnotationsVersion>3.3.0.ga</hibernateAnnotationsVersion> </properties> </project>
这样一来,我们只要引用这个 pom 就可以获得持久层了。
<dependency> <groupId>org.sonatype.mavenbook</groupId> <artifactId>persistence-deps</artifactId> <version>1.0</version> <type>pom</type> </dependency>
5. packing
打包的方式,默认 jar,可选 war。6. type
表示依赖的类型,默认 jar,之前也用到过 pom。相关文章推荐
- Maven Study Notes 1
- Spring study notes
- Selenium Study Notes
- study notes for EJB 3 in action (I)
- Portlet Study Notes (1)
- JspStudy套件部署j2ee maven项目网址问题
- JS study notes.
- Study notes for Decision Trees
- VBA Study Notes
- Study notes for OpenCV——第二节:Opencv的结构与内容
- Study notes for Sparse Coding
- Hash study notes
- Notes for R study
- study notes for EJB 3 in action (II)
- RNStudyNotes 研究与实践
- Study Notes of Neural Network Optimization(1)
- VBA Study Notes
- Asp.Net Design Pattern Studynotes -- Part1
- C++ muparser caculater study notes
- studyjams notes 1B-- layout weight