(三)maven依赖包
1.eclipse中创建maven项目
打开POM.xml ,添加依赖包
所有依赖都是通过坐标来搜索并引入jar包
坐标的要素:groupId,artifactId,version
附加要素:
scope 默认为compile,可选test,provided,runtime...
packaging 默认为jar,可选pom,war...
坐标的查询可以通过网上仓库进行查询:
http://mvnrepository.com/
<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>com.hqh.maven.user</groupId><artifactId>user-core</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>user-core</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- junit测试单元 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency><!-- 日志 --><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.6.1</version></dependency><!-- ORM --><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>3.6.10.Final</version></dependency><dependency><groupId>javassist</groupId><artifactId>javassist</artifactId><version>3.12.1.GA</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.25</version></dependency></dependencies></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> <groupId>com.hqh.maven.user</groupId> <artifactId>user-dao</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>user-dao</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- test范围的包不会被依赖导入,需要显示声明导入 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency><!-- 引入项目的另一个模块,所有user-core中compile范围的包都会传递到本项目中 --><dependency><groupId>com.hqh.maven.user</groupId><artifactId>user-core</artifactId><version>0.0.1-SNAPSHOT</version></dependency> </dependencies></project>
<dependency><groupId>com.hqh.maven.user</groupId><artifactId>user-log</artifactId><version>0.0.1-SNAPSHOT</version><exclusions><exclusion><groupId>log4j</groupId><artifactId>log4j</artifactId></exclusion></exclusions></dependency>
<dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.12</version></dependency>