Java web项目搭建系列之二 Jetty下运行项目

在项目pom.xml文件中添加Jetty运行配置

在pom.xml文件project节点下插入如下代码:

    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <contextPath>/hello</contextPath>
                </configuration>
            </plugin>
        </plugins>
        <finalName>
    hello
    </finalName>
    </build>

添加web.xml文件:

在【src】→【main】→【webapp】→【WEB-INF】文件夹下添加【web.xml】文件

web.xml文件中内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

</web-app>

国际惯例—Hello,World!:

在【webapp]目录下添加【index.html】文件,内容如下

<!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>HelloMaven</title>
</head>
<body>
    <h1>hello,world!</h1>
</body>
</html>

运行,查看结果:

在【HelloMaven】项目上,右击【Run As】→【Run Jetty】

下图为运行结果

原文地址:https://www.cnblogs.com/mtsl/p/4332433.html