zoukankan      html  css  js  c++  java
  • 如何通过Maven的Jetty插件运行Web工程

    强烈建议使用jetty9,因为据官方文档显示,Jetty 7 and Jetty 8 are now EOL (End of Life),如下:

    在pom.xml文件的<build></build>标签中加入如下配置:

    复制代码
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.4.v20170414</version>
            <configuration>
                <scanIntervalSeconds>5</scanIntervalSeconds>
                <webApp>
                         <contextPath>/</contextPath>
                </webApp>
            </configuration>
        </plugin>
    </plugins>
    复制代码

    配置说明:

        configuration.scanIntervalSeconds 配置表示新代码的扫描时间间隔(秒),值 <= 0 表示不扫描。这里利用的是jetty 的定时重载代码的特性,做修改后不用重新启动项目,自动扫描出改动后会自动更新class文件的。
        configuration.webApp.contextPath 配置表示工程的虚拟目录名,如果配置为/,则届时访问路径为hostname:port/,如果配置为/jetty,则届时访问路径为hostname:port/jetty,有点相当于namespace的作用。

    启动看效果,用Maven Build启动,需在Goals栏中配置如下:

    jetty:run -Djetty.port=9080

    或是直接在项目根目录下在命令行中用maven命令启动  mvn jetty:run -Djetty.port=9080

    其中9080是指定的端口,也可以在pom.xml文件中指定端口,且在pom.xml文件中指定的端口优先级要比Goals中指定的端口的优先级要高。配置如下:

    复制代码
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.4.v20170414</version>
            <configuration>
                <scanIntervalSeconds>5</scanIntervalSeconds>
                <webApp>
                    <contextPath>/</contextPath>
                </webApp>
                <connectors>
                    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <port>10000</port>
                    </connector>
                </connectors>
            </configuration>
        </plugin>
    </plugins>
    复制代码

    此时启动的话,如果在Goals也配置了-Djetty.port=9080,则有效的访问路径还是hostname:10000/,因为在pom.xml文件中配置的端口的优先级比较高!

    转自:https://www.cnblogs.com/koushr/p/5873384.html

  • 相关阅读:
    程序员式的幽默(灌水)
    你应该知道的
    WPF控件应用[0]
    WPF控件应用[2]
    C#调用Win32 的API函数User32.dll
    C#获取当前行号
    C#导入excel重写
    [转]wpf相关好资源
    使用C#和Excel进行报表开发-生成统计图Chart
    [转]用 delphi 创建一个服务程序
  • 原文地址:https://www.cnblogs.com/heqiyoujing/p/9505797.html
Copyright © 2011-2022 走看看