首页 > 代码库 > Spring MVC Maven项目配置(二)

Spring MVC Maven项目配置(二)

Maven项目中引入jar包,和平时引入Jar包有所不同,平时就是找到并下载jar包,用IDE导入就可以!

而maven项目引入了项目依赖Dependence的概念,项目中引入此jar包,代表此项目依赖此包,或者可以说这个包就是我项目的Dependence。

maven项目的Pom.xml文件,就是作为引入jar包的工具!

问一下百度叔叔,输入:Spring MVC maven项目需要哪些JAR包以及版本等等,就可以将你的包引入了!PS:通过<dependency>标签,输入Version,

artifactId、group_id等等,就是你的JAR包的名称、版本信息而已!

 

  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  3   <modelVersion>4.0.0</modelVersion>  4   <groupId>src.java</groupId><!-- 指定组名 -->  5   <artifactId>USER</artifactId><!--指定工作组名  -->  6   <packaging>war</packaging><!-- The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par -->  7   <version>0.0.1-SNAPSHOT</version><!-- 指定版本 -->  8   <name>USER Maven Webapp</name><!-- 可选 name url -->  9   <url>http://maven.apache.org</url> 10   <dependencies> 11     <dependency> 12       <groupId>junit</groupId> 13       <artifactId>junit</artifactId> 14       <version>3.8.1</version> 15       <scope>test</scope> 16     </dependency> 17     <!-- servlet --> 18     <dependency> 19       <groupId>javax.servlet</groupId> 20       <artifactId>javax.servlet-api</artifactId> 21       <version>3.1.0</version> 22       <scope>provided</scope> 23     </dependency> 24      25     <dependency> 26       <groupId>javax.servlet</groupId> 27       <artifactId>jstl</artifactId> 28       <version>1.2</version> 29     </dependency> 30          31     <dependency> 32       <groupId>javax.servlet</groupId> 33       <artifactId>jsp-api</artifactId> 34       <version>2.0</version> 35       <scope>provided</scope> 36     </dependency> 37      38     <!-- Spring --> 39     <dependency> 40       <groupId>org.springframework</groupId> 41       <artifactId>spring-jdbc</artifactId> 42       <version>4.0.3.RELEASE</version> 43     </dependency> 44      45     <dependency> 46       <groupId>org.springframework</groupId> 47       <artifactId>spring-context-support</artifactId> 48       <version>4.0.3.RELEASE</version> 49     </dependency> 50      51     <dependency> 52       <groupId>org.springframework</groupId> 53       <artifactId>spring-web</artifactId> 54       <version>4.0.3.RELEASE</version> 55     </dependency> 56      57     <dependency> 58       <groupId>org.springframework</groupId> 59       <artifactId>spring-webmvc</artifactId> 60       <version>4.0.3.RELEASE</version> 61     </dependency> 62      63        <!-- mybatis --> 64     <dependency> 65       <groupId>org.mybatis</groupId> 66       <artifactId>mybatis</artifactId> 67       <version>3.2.7</version> 68     </dependency> 69      70     <dependency> 71       <groupId>org.mybatis</groupId> 72       <artifactId>mybatis-spring</artifactId> 73       <version>1.2.2</version> 74     </dependency> 75     <!--jackson --> 76     <dependency> 77       <groupId>com.fasterxml.jackson.core</groupId> 78       <artifactId>jackson-databind</artifactId> 79       <version>2.2.3</version> 80     </dependency> 81  82     <dependency> 83       <groupId>org.codehaus.jackson</groupId> 84       <artifactId>jackson-core-asl</artifactId> 85       <version>1.9.13</version> 86     </dependency> 87     <!-- DB2 --> 88     <dependency> 89       <groupId>db2jcc</groupId> 90       <artifactId>db2jcc</artifactId> 91       <version>9.0</version> 92     </dependency> 93      94     <dependency> 95       <groupId>db2jcc_license_cu</groupId> 96       <artifactId>db2jcc_license_cu</artifactId> 97       <version>9.0</version> 98     </dependency> 99     100     <dependency>101       <groupId>commons-dbcp</groupId>102       <artifactId>commons-dbcp</artifactId>103       <version>1.4</version>104     </dependency>105     106     <dependency>107       <groupId>log4j</groupId>108       <artifactId>log4j</artifactId>109       <version>1.2.17</version>110       <exclusions>111         <exclusion>112           <groupId>javax.jms</groupId>113           <artifactId>jms</artifactId>114         </exclusion>115         <exclusion>116           <groupId>com.sun.jdmk</groupId>117           <artifactId>jmxtools</artifactId>118         </exclusion>119         <exclusion>120           <groupId>com.sun.jmx</groupId>121           <artifactId>jmxri</artifactId>122         </exclusion>123       </exclusions>124     </dependency>125     126     <dependency>127       <groupId>commons-codec</groupId>128       <artifactId>commons-codec</artifactId>129       <version>1.9</version>130     </dependency>131     132     <dependency>133       <groupId>com.google.code.gson</groupId>134       <artifactId>gson</artifactId>135       <version>2.2.4</version>136     </dependency>137     138             <!--jackson -->139         <dependency>140             <groupId>com.fasterxml.jackson.core</groupId>141             <artifactId>jackson-databind</artifactId>142             <version>2.2.3</version>143         </dependency>144 145         <dependency>146             <groupId>org.codehaus.jackson</groupId>147             <artifactId>jackson-core-asl</artifactId>148             <version>1.9.13</version>149         </dependency> 150         151 <!--         <dependency>152             <groupId>com.danga.MenCached</groupId>153             <artifactId>java_memcached-release</artifactId>154             <version>2.0.1</version>155         </dependency> 156      -->157      158 <!--      <dependency>159   <groupId>com.google.code.simple-spring-memcached</groupId>160   <artifactId>simple-spring-memcached-parent</artifactId>161   <version>3.1.0</version>162   <type>pom</type>163 </dependency>164 165  -->166 <dependency>167   <groupId>com.dango</groupId>168   <artifactId>memcached</artifactId>169   <version>2.0.1</version>170 </dependency>171 172 173   </dependencies>174   175   <build>176     <finalName>USER</finalName>177   </build>178 </project>

 

然后运行你的maven,Maven会自动下载所需的jar及相关的pom信息,Maven会帮你下载,并放到适当的位置,方便吧!呵呵~~

 

Maven的repository,说白了就是dependency的仓库,它按照一定的规则将dependency存放起来,以作缓存,如果本机的 repository找不到某个dependency,它就会自动去找到网上其它相关联的repository,找到的话将其下载至本地,那么下次它就不 再去其它地方下载了,直接从本地获取。 

 

本地的repository在哪可找到? 

默认repository地址:当前用户的私人目录 + .m2   如 C:\Users\c1307888\.m2

如果你之前设置了Maven目录下的conf/setting.xml的local repository属性,则不再是默认的repository地址,而使用你指定的地址。 

找到下面这段,将它复制一份,放到注释外面,改成你自己的repository路径即可 

<localRepository>c:\mvn repository\</localRepository> 

 

...待续

 

Spring MVC Maven项目配置(二)