maven项目的搭建——maven搭建spring mvc+ibatis项目(一)

怎么使用maven搭建spring mvc+ibatis框架项目呢?
首先,一览实例项目的总体,如图:
maven项目的搭建——maven搭建spring mvc+ibatis项目(一)


1、怎么建立一个maven项目呢?
新建Project--maven project,其他如下图所示:
maven项目的搭建——maven搭建spring mvc+ibatis项目(一)

maven项目的搭建——maven搭建spring mvc+ibatis项目(一)

2、在pom.xml中引入项目的所需要的jar包和编译的设置。
主要需要引入的有:
1)spring mvc相关的spring3.0以上的jar包
2)ibatis的jar包
3)数据库和数据库连接池应用的相关jar包,数据库是使用mysql的,采用dbcp连接方式
4)struts的json jar包
5)j2ee相关jar包


以下是项目的pom.xml文件内容,可供参考:
<?xml version="1.0" encoding="UTF-8"?>
<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.bluedon.ibatis</groupId>
  <artifactId>ibatis-root</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>ibatis-root Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <packaging>war</packaging>
  
  
  <!-- 版本配置 -->
	<properties>
		<struts.version>2.2.3</struts.version>
		<springframework.version>3.1.1.RELEASE</springframework.version>
		<ibatis.version>2.0.8</ibatis.version>
		<slf4j.version>1.7.5</slf4j.version>
		<jackson.version>1.8.4</jackson.version>
	</properties>
	
	
	<dependencies>
	    <dependency>
	      <groupId>junit</groupId>
	      <artifactId>junit</artifactId>
	      <version>3.8.1</version>
	      <scope>test</scope>
	    </dependency>
	    
	    <!-- j2ee -->
	    <dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.0.1</version>
		</dependency>
		
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.0</version>
		</dependency>
		
		<!-- mysql -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.27</version>
		</dependency>
		
		<!-- dbcp -->
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
		</dependency>
					
		<!-- struts json -->				
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-json-plugin</artifactId>
			<version>2.3.8</version>
		</dependency>
			
		<!-- spring -->		
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${springframework.version}</version>
		</dependency>
	
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${springframework.version}</version>
		</dependency>
	
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${springframework.version}</version>
		</dependency>
	
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		
		 <dependency>  
	        <groupId>org.springframework</groupId>  
	        <artifactId>spring-test</artifactId>  
	        <version>${springframework.version}</version>  
	    </dependency>  
	  
	    <dependency>  
	        <groupId>org.springframework</groupId>  
	        <artifactId>spring-tx</artifactId>  
	        <version>${springframework.version}</version>  
	    </dependency>
	    
	    <dependency>  
	        <groupId>org.springframework</groupId>  
	        <artifactId>spring-beans</artifactId>  
	        <version>${springframework.version}</version>  
	    </dependency>
	    
	    <dependency>  
	        <groupId>org.springframework</groupId>  
	        <artifactId>spring-jdbc</artifactId>  
	        <version>${springframework.version}</version>  
	    </dependency>
	    
	    <!-- ibatis-->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-ibatis</artifactId>
			<version>${ibatis.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.ibatis</groupId>
			<artifactId>ibatis-sqlmap</artifactId>
			<version>2.3.4.726</version>
		</dependency>
			
		<!-- slf4j+LOGBack-->
		<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>
		 <dependency>
			<groupId>org.slf4j</groupId>
	   		<artifactId>log4j-over-slf4j</artifactId>
			<version>${slf4j.version}</version>
		</dependency> 
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
	
		<!-- JSON begin -->
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-mapper-asl</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-core-asl</artifactId>
			<version>${jackson.version}</version>
		</dependency>
  </dependencies>
  
  <!-- 编译运行 -->
	<build>
		<plugins>
		
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-eclipse-plugin</artifactId>
				<configuration>
					<webAppConfig>
						<contextPath>/batis_root</contextPath>
					</webAppConfig>
					<additionalBuildcommands>
						<buildCommand>
							<name>org.eclipse.wst.common.project.facet.core.builder</name>
							<arguments>
							</arguments>
						</buildCommand>
					</additionalBuildcommands>
					<additionalProjectnatures>
						<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
						<projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
					</additionalProjectnatures>
					<classpathContainers>
						<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
					</classpathContainers>
					<wtpversion>2.0</wtpversion>
					<excludes>
					</excludes>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
				</configuration>
			</plugin>
			<plugin>  
                   <groupId>org.eclipse.m2e</groupId>  
                   <artifactId>lifecycle-mapping</artifactId>  
                   <version>1.0.0</version>  
                   <configuration>  
                       <lifecycleMappingMetadata>  
                           <pluginExecutions>  
                               <pluginExecution>  
                                   <pluginExecutionFilter>  
                                       <groupId>org.apache.maven.plugins</groupId>  
                                       <artifactId>maven-dependency-plugin</artifactId>  
                                       <versionRange>[2.0,)</versionRange>
                                       <goals>  
                                           <goal>copy-dependencies</goal>
                                           <goal>unpack-dependencies</goal>
                                       </goals>  
                                   </pluginExecutionFilter>  
                                   <action>  
                                       <ignore />  
                                   </action>  
                               </pluginExecution>  
                           </pluginExecutions>  
                       </lifecycleMappingMetadata>  
                   </configuration>  
               </plugin>
                
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>



相关maven服务器的搭建和pom.xml标签语法的使用可参见相关的文章。

你可能感兴趣的:(spring,maven,ibatis)