Eclipse Maven 创建Hello World Web项目

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

    先决条件 (Prerequisites)

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

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

3, Maven , 同上。

4,Eclipse 

    步骤:

1,File->New -> Project ->

 

点击Next

    

点击Next

    

 

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

    

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

    

  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>

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

    

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

 

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

posted @ 2019-04-16 15:39  潘彬  阅读(352)  评论(0编辑  收藏  举报