【问题标题】:hot deploying simple application in jetty在码头热部署简单的应用程序
【发布时间】:2010-03-04 02:59:23
【问题描述】:

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

目前,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>

我还创建了一个 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>

我也不确定如何在我阅读的调试模式下正确启动 Jetty,这也是需要的。我尝试使用以下方式启动服务器:

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

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

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

感谢您的帮助。

【问题讨论】:

    标签: java jakarta-ee jetty


    【解决方案1】:

    您需要定义一个具有非零扫描间隔的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>
    

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

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

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

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

    【讨论】:

    • 哦,所以我需要将它添加到我的项目 jetty.xml 文件中?例如,我试图在 myapp.xml 下的码头服务器的上下文目录中配置它。也感谢您提供调试信息!
    • @Casey 是的,我想是的(实际上,我总是使用 Maven 的 Jetty,所以我更习惯于配置 maven 插件,但这里的逻辑也适用)。顺便说一句,识别一个好的答案的常用方法是支持它;-)
    【解决方案2】:

    如果你想使用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>
    

    【讨论】:

    • 事实上,这正是我们团队现在正在做的事情。这几乎是所有需要的配置。此外,我们正在使用 Tapestry5,这种 maven/jetty 组合非常适合。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2013-01-13
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多