ssm框架搭建maven工程
阿新 • • 發佈:2018-12-10
2.1 在Eclipse中設定本地Maven
Maven選用的版本是3。我在本地裝了一個,然後在Eclipse中設定了一下。Maven的配置檔案
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>E:\GreenAPP\apache-maven-3.3.9\repo</localRepository> <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.complier.source>1.8</maven.complier.source> <maven.complier.target>1.8</maven.complier.target> <maven.complier.complierVersion>1.8</maven.complier.complierVersion> </properties> </profile> </profiles> </settings>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
2.2 建立Maven專案
2.2.1 Step by step
直接上圖了。Step 1Step 2
2.2.2 修正錯誤
有兩個地方不大對, 1. jre的版本 2. 缺少了web.xml檔案和web專案的資料夾。
修復過程如下: 1. 選中專案,右擊,選擇 properties,開啟對話方塊。修改Java的版本。並且去掉Dynamic Web Module的勾。
3. 輸入資料夾,勾選 Generated web.xml deployment descriptor,點選OK。
4. 可以看見生成的web.xml檔案和相應的資料夾。
2.3 編寫POM
2.3.1 新增方法
在Maven的 倉庫 中搜索需要新增的repository,選擇版本,在詳情頁面中直接拖拽repository的資訊到POM檔案中就行了。每次儲存POM檔案,專案都會自動重新整理jar包。
2.3.2 POM中需要加入的jar包:
- spring-webmvc : 4.3.13.RELEASE
- spring-jdbc: 4.3.13.RELEASE
- spring-aspects: 4.3.13.RELEASE
- spring-test: 4.3.13.RELEASE [test]
- mybatis : 3.4.5
- mybatis-spring : 1.3.1
- mybatis-generator-core : 1.3.5
- mysql-connector-java : 5.1.41
- c3p0 : 0.9.1
- jstl : 1.2
- servlet-api : 3.0
- junit : 4.12 [test]
這些是目前建立專案所需要的,隨著專案的繼續,再不斷完善和補充POM檔案。
2.4 POM檔案
<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.hh</groupId>
<artifactId>ssm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.13.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jstl/jstl -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<!-- 注意:使用 SpringMVC 的模擬測試時,需要 servlet 3.0 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
</project>