通过Eclipse创建Maven Web项目的简单步骤

    先决条件 (Prerequisites)

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

1,JDK  environment, 具体的安装JDK的步骤和环境配置一般网上都有,这里就不在赘述。

2,Tomcat , 同样具体的安装配置和环境配置,很容易找到相应的文章。

3, Maven , 同上。

4,Eclipse 

    步骤:

1,File->New -> Project ->

 Eclipse Maven 创建Hello World Web项目 随笔 第1张

点击Next

    Eclipse Maven 创建Hello World Web项目 随笔 第2张

点击Next

    Eclipse Maven 创建Hello World Web项目 随笔 第3张

 

  2,点击finish,待目录结构生成之后会出现如下错误,

    Eclipse Maven 创建Hello World Web项目 随笔 第4张

我们需要创建如下目录结构,在webapp文件夹下

    Eclipse Maven 创建Hello World Web项目 随笔 第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" 
    id="WebApp_ID" version="3.1">
    
    <display-name>maven-web-test</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>login.html</welcome-file>
     </welcome-file-list>    
    
  
</web-app>

然后再创建i相应的index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
</head>
    <body>
        <center>Hellow World!!</center>
    </body>
</html>

这时应该会是有如下错误,

    Eclipse Maven 创建Hello World Web项目 随笔 第6张

    我们需要以下步骤解决:右键项目名称->Build Path->Configure Build Path->Add Libary->选择Server Runtime->选择相应的Tomcat容器->Finish->Apply Close

 

然后Hello World 的maven项目就建好了,项目运行的步骤:右击项目名称->Run As -> Run on Server->选择相应的Tomcat

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄