在Eclipse中使用Maven创建Web工程

在Eclipse中使用Maven创建Web工程

  1、创建maven Project工程,使用maven-archetype-webapp

                                            

  2、在pom.xml文件中,设置打包类型为war

      <packaging>war</packaging>

  3、在webapp下新建WEB-INF目录和web.xml配置文件

      快捷方法:右键项目——>Java EE Tools——>Generate Deployment Descriptor Stub快速生成WEB-INF目录和web.xml配置文件

  4、在项目的pom.xml文件中配置servlet和jsp依赖(必要的话配置junit依赖)

 1 <dependencies>
 2     <dependency>
 3         <groupId>junit</groupId>
 4         <artifactId>junit</artifactId>    <!-- junit依赖 -->
 5         <version>4.9</version>
 6         <scope>test</scope>
 7     </dependency>
 8     <dependency>
 9         <groupId>javax.servlet</groupId>
10         <artifactId>servlet-api</artifactId>    <!-- servlet依赖 -->
11         <version>2.5</version>
12         <scope>provided</scope>
13     </dependency>
14     <dependency>
15         <groupId>javax.servlet</groupId>
16         <artifactId>jsp-api</artifactId>    <!-- jsp依赖 -->
17         <version>2.0</version>
18         <scope>provided</scope>
19     </dependency>
20   </dependencies>
原文地址:https://www.cnblogs.com/java-zmj/p/7979052.html