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>DemoartifactId>
        <groupId>me.jtzen9groupId>
        <version>1.0-SNAPSHOTversion>
    parent>

    <modelVersion>4.0.0modelVersion>
    <artifactId>demo-jettyartifactId>
    <packaging>warpackaging>

    <name>demo-jetty Maven Webappname>
    <url>http://maven.apache.orgurl>

    <properties>
        <jetty.maven.plugin.version>9.4.7.v20170914jetty.maven.plugin.version>
    properties>

    <build>
        <finalName>demo-jettyfinalName>

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

                    <httpConnector>
                        
                        <port>8888port>
                        
                        <idleTimeout>60000idleTimeout>
                    httpConnector>

                    

                    
                    <scanIntervalSeconds>2scanIntervalSeconds>
                    <reload>automaticreload>

                    
                    <dumpOnStart>falsedumpOnStart>

                    
                    <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
                        
                        <filename>target/yyyy_mm_dd.request.logfilename>
                        
                        
                        <retainDays>90retainDays>
                        
                        <append>trueappend>
                        <extended>falseextended>
                        
                        <logTimeZone>GMT+8:00logTimeZone>
                    requestLog>

                    <stopPort>9966stopPort>
                    <stopKey>jtzen9stopKey>
                    <stopWait>10stopWait>

                    <webAppSourceDirectory>src/main/webappwebAppSourceDirectory>
                    <webApp>
                        
                        <contextPath>/demo-jettycontextPath>
                        
                        
                    webApp>

                configuration>
            plugin>
        plugins>
    build>

project>

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



<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    
    <New id="showcase" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>jdbc/showcaseArg>
        <Arg>
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="driverClassName">oracle.jdbc.driver.OracleDriverSet>
                <Set name="url">jdbc:oracle:thin:@127.0.0.1:1521/orclSet>
                <Set name="username">scottSet>
                <Set name="password">scottSet>
                <Set name="maxActive">10Set>
            New>
        Arg>
    New>
Configure>

1.3 启动

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

2 Jetty服务类

说明

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

你可能感兴趣的:(Java,EE学习笔记)