1

我已经通过 context.xml 设置了一个 Jetty 上下文以使用虚拟主机。所以我的目录结构是这样的:

webapps
--mycontext.xml
--mycontext.war

现在,当我上传新战争时,不再发生热部署。它仅在我修改 mycontext.xml 时发生。当我在没有 mycontext.xml 的情况下工作时,情况并非如此。

这是 mycontext.xml 的内容

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

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

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <!-- Required minimal context configuration :                        -->
 <!--  + contextPath                                                  -->
 <!--  + war OR resourceBase                                          -->
 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <Set name="contextPath">/</Set>
 <Set name="war"><Property name="jetty.webapps" default="."/>/mycontext.war</Set>

 <Set name="virtualHosts">
   <Array type="String">
     <Item>example.com</Item>
      <Item>www.example.com</Item>
      <Item>localhost</Item>
     <Item>127.0.0.1</Item>
   </Array>
 </Set>
</Configure>

任何想法我如何通过更新战争文件重新获得热部署?

4

1 回答 1

0

您需要将 mycontext.xml 放在服务器的 contexts 目录中。此外,您可能需要在 etc/jetty-deploy.xml 中为 webapps 目录中的 war 文件启用热部署,如此处所述。如您所见,配置启用了热部署

......
 <Set name="monitoredDirName"><Property name="jetty.home" default="." />/webapps</Set>
.....

以下是对我有用的配置

jetty.home/contextx/mycontext.xml

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

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

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <!-- Required minimal context configuration :                        -->
 <!--  + contextPath                                                  -->
 <!--  + war OR resourceBase                                          -->
 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <Set name="contextPath">/mycontext</Set>
 <Set name="war"><SystemProperty name="jetty.home"/>/webapps/mycontext.war</Set>

 <Set name="virtualHosts">
   <Array type="String">
     <Item>example.com</Item>
      <Item>www.example.com</Item>
      <Item>localhost</Item>
     <Item>127.0.0.1</Item>
   </Array>
 </Set>
</Configure>

请注意我是如何提供战争文件名和位置的

 <Set name="war"><SystemProperty name="jetty.home"/>/webapps/mycontext.war</Set>

jetty.home/etc/jetty-deploy.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- =============================================================== -->
<!-- Create the deployment manager                                   -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The deplyment manager handles the lifecycle of deploying web    -->
<!-- applications. Apps are provided by instances of the             -->
<!-- AppProvider interface.  Typically these are provided by         -->
<!-- one or more of:                                                 -->
<!--   jetty-webapps.xml       - monitors webapps for wars and dirs  -->
<!--   jetty-contexts.xml      - monitors contexts for context xml   -->
<!--   jetty-templates.xml     - monitors contexts and templates     -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <Call name="addBean">
      <Arg>
        <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
          <Set name="contexts">
            <Ref id="Contexts" />
          </Set>
          <Call name="setContextAttribute">
            <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
            <Arg>.*/servlet-api-[^/]*\.jar$</Arg>
          </Call>


          <Call id="webappprovider" name="addAppProvider">
          <Arg>
            <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
              <Set name="monitoredDirName"><Property name="jetty.home" default="." />/webapps</Set>
              <Set name="defaultsDescriptor"><Property name="jetty.home" default="." />/etc/webdefault.xml</Set>
              <Set name="scanInterval">1</Set>
              <Set name="extractWars">true</Set>
            </New>
          </Arg>
        </Call>

        </New>
      </Arg>
    </Call>
</Configure>

有了这个配置,当我把修改后的 mycontext.war 放到 webapps 中时,jetty 很高兴地重新部署了 war。

于 2013-10-26T18:00:10.290 回答