java 在jetty中热部署简单的应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2376596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:51:05  来源:igfitidea点击:

hot deploying simple application in jetty

javajakarta-eejetty

提问by Casey

I am working with jetty hightide vesion 7 currently as a stand alone server. I have a simple web project with a couple of jsp's and backing classes that I am currently deploying in an unexploded war to the JETTY_HOME/webapps directory.

我目前正在使用 jetty hightide vesion 7 作为独立服务器。我有一个简单的 web 项目,其中包含几个 jsp 和支持类,我目前正在将它们部署到 JETTY_HOME/webapps 目录的未爆炸War中。

Currently, jetty easily picks up any static jsp/html changes. If I understand correctly, I can configure my app so that jetty will pick up any class changes without restarting the server? I currently have in my jetty-web.xml:

目前,jetty 可以轻松获取任何静态 jsp/html 更改。如果我理解正确,我可以配置我的应用程序,以便码头可以在不重新启动服务器的情况下接收任何类更改?我目前在我的 jetty-web.xml 中有:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!--
    This is the jetty specific web application configuration file. When
    starting a Web Application, the WEB-INF/web-jetty.xml file is looked
    for and if found, treated as a
    org.eclipse.jetty.server.server.xml.XmlConfiguration file and is
    applied to the org.eclipse.jetty.servlet.WebApplicationContext objet
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call class="org.eclipse.jetty.util.log.Log" name="debug">
    <Arg>executing jetty-web.xml</Arg>
</Call>
<Set name="contextPath">/SimpleDynamicProject</Set>

</Configure>

I also have created a SimpleDynamicProject.xml and put it in JETTY_HOME/contexts. This file contains:

我还创建了一个 SimpleDynamicProject.xml 并将其放在 JETTY_HOME/contexts 中。该文件包含:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!--
    This is the jetty specific web application configuration file. When
    starting a Web Application, the WEB-INF/web-jetty.xml file is looked
    for and if found, treated as a
    org.eclipse.jetty.server.server.xml.XmlConfiguration file and is
    applied to the org.eclipse.jetty.servlet.WebApplicationContext objet
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<Set name="contextPath">/SimpleDynamicProject</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/SimpleDynamicProject</Set>
</Configure>

I am also not sure how to correctly start Jetty in debug mode which I read was also needed. I have tried starting the server with:

我也不确定如何在调试模式下正确启动 Jetty,我也读到过。我尝试使用以下命令启动服务器:

java -Xdebug -jar start.jar OPTIONS=Server,jsp

and

java -Ddebug -jar start.jar OPTIONS=Server,jsp

This is the first time I've used jetty, but so far I really like it.

这是我第一次使用jetty,但到目前为止我真的很喜欢它。

Thanks for the help.

谢谢您的帮助。

采纳答案by Maciek Kreft

If you want to use jetty maven plugin

如果你想使用jetty maven插件

   <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.25</version>
        <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
            <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
                <!--
                          This doesn't do anything for Jetty, but is a workaround for a
                          Maven bug that prevents the requestLog from being set.
                      -->
                <append>true</append>
            </requestLog>
            <webApp>${basedir}/out/war/Spring2_5_6_war.war</webApp>
        </configuration>
    </plugin>

回答by Pascal Thivent

You need to define a ContextDeployerwith a non-zero scan interval:

您需要定义一个具有非零扫描间隔的ContextDeployer

<Call name="addLifeCycle">
  <Arg>
    <New class="org.mortbay.jetty.deployer.ContextDeployer">
      <Set name="contexts"><Ref id="Contexts"/></Set>
      <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
      <Set name="scanInterval">1</Set>
    </New>
  </Arg>
</Call>

Regarding debugging, I guess that what you have in mind is to connect a remote debugger using JPDA. For this, you'll need to set the -agentlib:jdwpoption1:

关于调试,我猜您想到的是使用 JPDA 连接远程调试器。为此,您需要设置-agentlib:jdwp选项1

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

The configure your IDE debugger to connect on the specified port.

配置您的 IDE 调试器以连接到指定的端口。

1if the target VM is 5.0 or newer, -agentlib:jdwpis preferable over the -Xdebugand -Xrunjdwpoptions which are still supported though.

1如果目标 VM 是 5.0 或更高版本,-agentlib:jdwp则比仍然支持的-Xdebug-Xrunjdwp选项更可取。