在eclipse中创建基于maven的springmvc web工程
做一个过程记录
1、eclipse下新建web工程:
一路next,给工程命名好,创建好。
2、在菜单中,工程上鼠标右键,将工程转换为maven工程
3、找到pom.xml文件,copy下列内容进去:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.alex</groupId>
<artifactId>com.alex.springmvcweb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>com.alex.springmvcweb Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<finalName>com.alex.springmvcweb</finalName>
</build>
<properties>
<springVersion>3.2.5.RELEASE</springVersion>
</properties>
</project>
4、根据需要,可以在pom中再加入其他maven依赖,例如:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
5、调用maven install 下载更新所依赖的库的jar包
6、部署到tomcat进行运行调试
整个过程很简单,但是新手往往会遇到各种问题,主要有:
1、maven本地库没配置好,或者在eclipse中没有配置好maven环境
2、tomcat没有安装好,或者eclipse中没有配置好tomcat环境
3、jre的版本可能存在兼容性问题
可能还会有其他小问题,过程中不要着急,根据错误提示,很快能够解决问题。