Jetty运行web项目

1 jetty-maven-plugin

1.1 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
        <artifactId>Demo</artifactId>
        <groupId>me.jtzen9</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>demo-jetty</artifactId>
    <packaging>war</packaging>

    <name>demo-jetty Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <jetty.maven.plugin.version>9.4.7.v20170914</jetty.maven.plugin.version>
    </properties>

    <build>
        <finalName>demo-jetty</finalName>

        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.maven.plugin.version}</version>
                <configuration>

                    <httpConnector>
                        <!-- 服务器端口号 -->
                        <port>8888</port>
                        <!-- Maximum idle time for a connection -->
                        <idleTimeout>60000</idleTimeout>
                    </httpConnector>

                    <!--<jettyXml>src/main/resources/jetty-env.xml</jettyXml>-->

                    <!-- 自动扫描文件改变并进行热部署的时间间隔,默认值0,代表着禁用扫描并热部署. -->
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <reload>automatic</reload>

                    <!-- 可选择的配置,默认false,启动时是否打印出server的结构。 -->
                    <dumpOnStart>false</dumpOnStart>

                    <!-- 请求log -->
                    <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
                        <!-- log输出目录-->
                        <filename>target/yyyy_mm_dd.request.log</filename>
                        <!--<filenameDateformat>yyyy_MM_dd</filenameDateformat>-->
                        <!-- log保存天数-->
                        <retainDays>90</retainDays>
                        <!-- log是否附加在文件后-->
                        <append>true</append>
                        <extended>false</extended>
                        <!-- 时区-->
                        <logTimeZone>GMT+8:00</logTimeZone>
                    </requestLog>

                    <stopPort>9966</stopPort>
                    <stopKey>jtzen9</stopKey>
                    <stopWait>10</stopWait>

                    <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
                    <webApp>
                        <!-- 项目根目录 -->
                        <contextPath>/demo-jetty</contextPath>
                        <!-- 当前web应用的web.xml路径 -->
                        <!--<descriptor></descriptor>-->
                    </webApp>

                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

1.2 src/main/resources/jetty-env.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
        "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <!-- 应用数据源 -->
    <New id="showcase" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>jdbc/showcase</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="driverClassName">oracle.jdbc.driver.OracleDriver</Set>
                <Set name="url">jdbc:oracle:thin:@127.0.0.1:1521/orcl</Set>
                <Set name="username">scott</Set>
                <Set name="password">scott</Set>
                <Set name="maxActive">10</Set>
            </New>
        </Arg>
    </New>
</Configure>

1.3 启动

运行时候只要maven build->输入jetty:run即可

2 Jetty服务类

说明

参考:web项目嵌入Jetty运行的两种方式(Jetty插件和自制Jetty服务器)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值