- 环境配置
从maven官网下载压缩包并解压到电脑中,配置系统环境变量:
新建MAVEN_HOME:D:\maven\apache-maven-3.5.0
配置系统变量Path:%MAVEN_HOME%\bin;
- 检测maven是否配置成功
- 设置maven本地仓库存储地址
- 在eclipse中配置maven
- 在eclipse中用maven构建第一个wab项目
- 给maven项目添加jdk插件及tomcat插件.,在pom.xml中配置
- <!-- 添加项目jdk编译插件 --><build><plugins><!-- 编译版本设为1.8 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><uriEncoding>UTF-8</uriEncoding><port>8080</port><path>1maven</path></configuration></plugin></plugins></build>
添加这些代码之后,选中项目 Maven --> update project..跟新jdk和tomcat为自己设点的版本
7.添加测试类sevlet(直接用servlet工具,其会自动在web.xml中配置)
解决方法:添加对应的jar包
修改servlet中代码:
package com.ctgu;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class HelloMaven extends HttpServlet {private static final long serialVersionUID = 1L; public HelloMaven() { }protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html;charset=utf-8");response.getWriter().write("hello world");}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doGet(request, response);}}
8.运行maven项目 Run --> Maven build...
9.运行成功并访问