用maven创建web项目(spring Mvc)

 

 

用maven创建web项目(spring Mvc)

 

1、打开cmd进入到你要创建maven项目的目录下:

2、输入以下命令、然后根据提示输入相应的groupId、artifactId、version:

mvn archetype:generate -DarchetypeCatalog=internal 

3、这时maven会自动帮你拉包,我这里是groupId=com.GetcharZp.demo,artifactId=SpringMvnDemo,version为默认;

4、将下面的pom.xml 文件做以下修改;

  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3   <modelVersion>4.0.0</modelVersion>
  4   <groupId>com.GetcharZp.demo</groupId>
  5   <artifactId>SpringMvcDemo</artifactId>
  6   <packaging>war</packaging>
  7   <version>1.0-SNAPSHOT</version>
  8   <name>SpringMvcDemo Maven Webapp</name>
  9   <url>http://maven.apache.org</url>
 10 
 11 
 12  <properties>
 13     <aspectj.version>1.8.9</aspectj.version>
 14   </properties>
 15 
 16 
 17   <dependencies>
 18     <dependency>
 19       <groupId>junit</groupId>
 20       <artifactId>junit</artifactId>
 21       <version>3.8.1</version>
 22       <scope>test</scope>
 23     </dependency>
 24 
 25 
 26       <dependency>
 27         <groupId>javax.servlet</groupId>
 28         <artifactId>javax.servlet-api</artifactId>
 29         <version>3.1.0</version>
 30       </dependency>
 31 
 32 
 33       <dependency>
 34         <groupId>javax.servlet</groupId>
 35         <artifactId>jstl</artifactId>
 36         <version>1.1.2</version>
 37         <type>jar</type>
 38       </dependency>
 39       <dependency>
 40         <groupId>taglibs</groupId>
 41         <artifactId>standard</artifactId>
 42         <version>1.1.2</version>
 43         <type>jar</type>
 44       </dependency>
 45 
 46 
 47 
 48     <dependency>
 49       <groupId>org.springframework</groupId>
 50       <artifactId>spring-webmvc</artifactId>
 51       <version>4.3.4.RELEASE</version>
 52     </dependency>
 53 
 54 
 55     <dependency>
 56       <groupId>org.aspectj</groupId>
 57       <artifactId>aspectjrt</artifactId>
 58       <version>${aspectj.version}</version>
 59     </dependency>
 60 
 61     <dependency>
 62       <groupId>org.aspectj</groupId>
 63       <artifactId>aspectjweaver</artifactId>
 64       <version>${aspectj.version}</version>
 65     </dependency>
 66     
 67 
 68     <dependency>
 69       <groupId>com.fasterxml.jackson.core</groupId>
 70       <artifactId>jackson-core</artifactId>
 71       <version>2.7.5</version>
 72     </dependency>
 73     <dependency>
 74       <groupId>com.fasterxml.jackson.core</groupId>
 75       <artifactId>jackson-databind</artifactId>
 76       <version>2.7.5</version>
 77     </dependency>
 78     <dependency>
 79       <groupId>com.fasterxml.jackson.core</groupId>
 80       <artifactId>jackson-annotations</artifactId>
 81       <version>2.7.5</version>
 82     </dependency>
 83 
 84 
 85     <dependency>
 86       <groupId>org.hibernate</groupId>
 87       <artifactId>hibernate-validator</artifactId>
 88       <version>5.3.4.Final</version>
 89     </dependency>
 90     
 91 
 92     <dependency>
 93       <groupId>commons-fileupload</groupId>
 94       <artifactId>commons-fileupload</artifactId>
 95       <version>1.3.3</version>
 96     </dependency>
 97   
 98 
 99   </dependencies>
100   <build>
101     <finalName>mvcdemo</finalName>
102     <plugins>
103       <plugin>
104         <groupId>org.apache.maven.plugins</groupId>
105         <artifactId>maven-compiler-plugin</artifactId>
106         <version>3.6.0</version>
107 
108         <configuration>
109           <source>8</source>
110           <target>8</target>
111           <encoding>UTF-8</encoding>
112         </configuration>
113       </plugin>
114   </plugins>
115   </build>
116 </project>

5、web.xml文件做以下修改:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>mvcdemo</display-name>
 
</web-app>

6、通过cmd命令cd到你的项目下(我这里是)

cd SpringMvcDemo

7、编辑

mvn compile

8、最后导入eclipse...

posted @ 2018-07-06 10:20  GetcharZp  阅读(451)  评论(0编辑  收藏  举报