在pom.xml中添加java ee相关的三个依赖包:<scope> jar的有效范围 provided 表示编译期生效,不会打包发布到 tomcat 中
<properties> <servlet-version>3.0.1</servlet-version> <jsp-version>2.2</jsp-version> <jstl-version>1.2</jstl-version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet-version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>${jsp-version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl-version}</version> </dependency> </dependencies>
在pom.xml中配置 tomcat 插件
<build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <!-- tomcat端口号 --> <port>80</port> <!-- 项目发布到tomcat后的名称,/ 相当于把项目发布名称为ROOT,名称格式:/cppdy --> <path>/</path> </configuration> </plugin> </plugins> </build>
右键项目--> run as --> maven build-->Goals 中输入clean tomcat7:run
打开浏览器访问localhost