pom.xml--SSM框架搭建時利用Maven匯入所需要的jar包
阿新 • • 發佈:2019-02-02
<span style="font-family:Comic Sans MS;font-size:18px;"><strong>下面是搭建SSM框架時Maven pom.xml配置檔案:在這裡總結下,方便下次使用</strong></span>
<span style="font-family:Comic Sans MS;"><strong>
</strong></span>
<span style="font-family:Comic Sans MS;"><strong><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.zju.ccnt</groupId> <artifactId>Login_ssm_mav</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>Login_ssm_mav</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- spring版本號 --> <spring.version>3.2.4.RELEASE</spring.version> <!-- mybatis版本號 --> <mybatis.version>3.2.4</mybatis.version> <!-- log4j日誌檔案管理包版本 --> <slf4j.version>1.6.6</slf4j.version> <log4j.version>1.2.9</log4j.version> </properties> <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <!-- scope=compile 的情況(預設compile),也就是說這個專案在編譯、測試,執行階段都需要這個artifact對應的jar包在classpath中 --> <!-- scope=provided ,則可以認為這個provided是目標容器已經provided這個artifact,它隻影響到編譯、測試階段,執行階段,假定目標容器已經提供了這個jar包 --> <scope>provided</scope> </dependency> <!-- 匯入dbcp的jar包,用來在applicationContext.xml中配置資料庫 --> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8</version> <scope>test</scope> </dependency> <!-- 上傳元件包 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.9</version> </dependency> <!-- 映入JSON --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <!-- 格式化物件,方便輸出日誌 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.41</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>jsp-api</artifactId> <version>6.0.32</version> <scope>provided</scope> </dependency> <!-- spring 核心包 --> <!-- springframe start --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-content-support</artifactId> <version>${spring.version}</version> </dependency> --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- springframe end --> <!-- mybatis核心包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> <!-- mybatis/spring包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <!--oracle驅動包 --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency> <!-- 資料來源包 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.2</version> </dependency> <!-- json資料 --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <!-- 日誌檔案管理包 --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- log end --> </dependencies> <!-- 定製打包後的包名 --> <build> <finalName>springmvc</finalName> </build> </project> </strong></span>
</pre><pre name="code" class="html"><span style="font-family:Comic Sans MS;"><strong>該檔案最開始出錯,直接進入到專案的根目錄執行 mvn compile自動下載好所需要的jar包</strong></span>
<span style="font-family:Comic Sans MS;"><strong>如果網速不好,或者maven倉庫不存在jar的情況導致compile時出錯,可以再次嘗試 mvn compile </strong></span>
<span style="font-family:Comic Sans MS;"><strong>
</strong></span>
如果是maven遠端倉庫中不存在jar包,下面以oracle的驅動包 ojdbc.jar為例
ojdbc6.jar的匯入方法:
ojdbc14.jar匯入方法:<span style="font-family:Comic Sans MS;"><dependency> <groupid>com.oracle</groupid> <artifactid>ojdbc6</artifactid> <version>11.2.0.1.0</version> </dependency></span>
<span style="font-family:Comic Sans MS;"><strong><dependency>
<groupid>com.oracle</groupid>
<artifactid>ojdbc14</artifactid>
<version>10.2.0.4.0</version>
</dependency></strong></span>
與匯入其他jar包相同,在專案pom.xml檔案中,可以採用Dependencies嚮導搜尋並匯入程式碼,可以發現 GroupId 為com.oracle,
ArtifactId為ojdbc14,目前最新版本為10.2.0.4.0,所以有上述程式碼。
如果是一些常見的包,在這步結束後就算匯入成功了,但是對於Oralce來說,我們看到的並非這樣,pom.xml打了個紅叉,這是因為Oracle JDBC驅動包是需要Oracle官方授權才能被下載,Apache併為提供ojdbc.jar的公開下載(http://search.maven.org/),這一點可到Maven的本地庫目錄中找,例如我的ojdbc14.jar存在我的這個目錄中:E:\Program\spring-framework-3.0\lib\Oracle
然後在命令列中執行如下語句
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=E:\Program\spring-framework-3.0\lib\Oracle\ojdbc14-10.2.0.4.0.jar
執行完後,我們可以在目錄C:\Users\Administrator\.m2\repository\com\oracle\ojdbc14\10.2.0.4.0下找到包ojdbc14-10.2.0.4.0.jar,重新整理專案,成功。
注意上面的install-file 這個- 和install之間不要有空格,我就是一直加了個空格所以一直出錯。