1.创建Maven项目:
点击“File”菜单,或者通过工具栏的“New”创建Project,如下图所示:
选择Maven-》Maven Project,弹出向导对话框,如下图所示:
选中Create a simple project……复选框,其它的设置不变,并点击Next,输入maven项目必须的信息(groupId,artifactid,version),如下图所示:
这里需要选择Packaging,web项目一般选择war即可。点击Finish,完成项目创建,下图为创建的项目结构(项目名称为:sample-webapp):
2.配置web项目:
右键点击sample-webapp项目,依次点击Properties-》Project Facets-》Convert to faceted form… ,如下图所示:
勾选Dynamic Web Module,并选择版本(这里使用2.5,由于3.0版本需要tomcat7),如下图所示:
点击OK,此时,项目结构树增加了WebContent文件夹,如下图所示:
将WebContent下的WEB-INF、META-INF文件夹copy到src/main/webapp目录下,并且删除WebContent目录,完成之后,如下图所示:
右键点击sample-webapp项目,依次点击Properties-》Deployment Assembly,如下图所示:
此时,通过Remove按钮删除/src/test/java、/src/test/resources、/WebContent,并且通过Add添加webapp与maven依赖,如下图所示:
首先Add-》Folder,选择webapp目录并Finish,再选择Java Build Path Entries-》Maven Dependencies
完成之后,如下图所示:
3.部署web项目:
添加tomcat server,并部署web项目,这里不描述,与非maven项目基本相同。
springmvc+mybatis使用到的一些jar包
pom.xml
<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>cn.aslan</groupId>
<artifactId>0319_webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies> <!-- 远程依赖库 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- 1.日志 -->
<!--<!– 实现slf4j接口并整合 –>-->
<!--<dependency>-->
<!--<groupId>ch.qos.logback</groupId>-->
<!--<artifactId>logback-classic</artifactId>-->
<!--<version>1.1.1</version>-->
<!--</dependency>-->
<!--log4j2支持-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${org.apache.logging.log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${org.apache.logging.log4j.version}</version>
</dependency>
<!-- 2.数据库 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency>
<!--druid==>阿里巴巴数据库连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${com.alibaba.druid.version}</version>
</dependency>
<!--<dependency>-->
<!--<groupId>c3p0</groupId>-->
<!--<artifactId>c3p0</artifactId>-->
<!--<version>0.9.1.2</version>-->
<!--</dependency>-->
<!-- DAO: MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${com.mybatis.mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${com.mybatis.mybatis_spring.version}</version>
</dependency>
<!-- 3.Servlet web -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--json工具-->
<!--<dependency>-->
<!--<groupId>com.fasterxml.jackson.core</groupId>-->
<!--<artifactId>jackson-databind</artifactId>-->
<!--<version>2.5.4</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${com.google.gson.version}</version>
</dependency>
<!--Servlet版本设置-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version>
</dependency>
<!-- 4.Spring -->
<!-- 1)Spring核心 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- 2)Spring DAO层 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- 3)Spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- 4)Spring test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- redis客户端:Jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${redis.clients.version}</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>${com.dyuproject.protostuff.version}</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>${com.dyuproject.protostuff.version}</version>
</dependency>
<!-- Map工具类 -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<!--文件上传工具-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-pool/commons-pool -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.0.Final</version>
</dependency>
</dependencies>
<!-- 配置可变版本号,也就是常说的版本管理 (Spring、SpringMvc、Mybatis、Gson、Druid) -->
<!-- 要针对某个依赖进行升级的时候只需要更改下面对应的版本号 -->
<!-- 在上面使用版本号的时候需要用固定格式,如: ${包名.version} -->
<properties>
<org.apache.logging.log4j.version>2.6.2</org.apache.logging.log4j.version>
<mysql.version>5.1.37</mysql.version>
<com.alibaba.druid.version>1.0.25</com.alibaba.druid.version>
<com.mybatis.mybatis.version>3.4.1</com.mybatis.mybatis.version>
<com.mybatis.mybatis_spring.version>1.3.0</com.mybatis.mybatis_spring.version>
<com.google.gson.version>2.7</com.google.gson.version>
<javax.servlet.version>3.1.0</javax.servlet.version>
<org.springframework.version>4.3.2.RELEASE</org.springframework.version>
<redis.clients.version>2.7.3</redis.clients.version>
<com.dyuproject.protostuff.version>1.0.8</com.dyuproject.protostuff.version>
<developer.organization><![CDATA[scengine]]></developer.organization>
</properties>
<!-- 构建项目的最终名称 -->
<build>
<finalName>SSM_LOG</finalName>
</build>
</project>