在码头定义webapp加载顺序 [英] defining webapp load order in jetty

查看:90
本文介绍了在码头定义webapp加载顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Web应用程序,它们可能分别部署或部署在同一码头服务器中.在我的情况下,一个Web应用程序必须先部署,然后另一个Web应用程序才能完成其部署,因此我正在寻找一种在双重部署情况下可以定义部署顺序的解决方案.

I have two webapps that might be deployed separately or in the same jetty server. In my situation, one webapp must deploy before the other can complete its deployment, so I'm looking for a solution in the dual deployment case where I can define the deployment order.

我已使用以下内容定义了上下文xml文件:

I've defined a context xml file with the following:

<?xml version="1.0"  encoding="ISO-8859-1"?>
 <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
   "http://www.eclipse.org/jetty/configure.dtd">
  <Configure class="org.eclipse.jetty.server.handler.HandlerList">
    <New class="org.eclipse.jetty.server.handler.HandlerList">
      <Set name="handlers">
        <Array type="org.eclipse.jetty.server.Handler">
          <Item>
            <New class="org.eclipse.jetty.webapp.WebAppContext">
             <Set name="contextPath">/security</Set>
             <Set name="war"><SystemProperty name="jetty.home"/>/security_app/war/</Set>
             <Call name="addAliasCheck">
               <Arg>
                <New class="org.eclipse.jetty.server.handler.ContextHandler$ApprovePathPrefixAliases"/>
               </Arg>
             </Call>
           </New>
         </Item>
         <Item>
           <New class="org.eclipse.jetty.webapp.WebAppContext">
             <Set name="contextPath">/</Set>
             <Set name="war"><SystemProperty name="jetty.home"/>/main_app/war/</Set>
             <Call name="addAliasCheck">
               <Arg>
                 <New class="org.eclipse.jetty.server.handler.ContextHandler$ApprovePathPrefixAliases"/>
               </Arg>
             </Call>
           </New>
         </Item>
       </Array>
     </Set>
   </New>
 </Configure>

但是,通过这种解决方案,我收到以下错误:

However, with this solution, I get the following error:

java.lang.ClassCastException: org.eclipse.jetty.server.handler.HandlerList cannot be cast to org.eclipse.jetty.server.handler.ContextHandler
at org.eclipse.jetty.deploy.providers.WebAppProvider.createContextHandler(WebAppProvider.java:292)
at org.eclipse.jetty.deploy.App.getContextHandler(App.java:101)
at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:605)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)

这当然是对的,尽管最后它们都是AbstractHandlers.我可能做错了什么,还是有另一种方法可以解决这个问题?

which of course, is true, though they both are AbstractHandlers in the end. What might I be doing wrong or is there another way to pull this off?

使用码头9.2.1

谢谢

推荐答案

您已对部署进行了硬编码,请不要使用 deploy 模块.

You have hardcoded deployments, don't use the deploy module.

您遇到的异常是 deploy 模块尝试查找和部署Webapp本身,但没有找到 org.eclipse.jetty.server.handler.ContextHandler 期望进入.

The exception you are getting is the deploy module attempting to find and deploy webapps itself, and is failing to find the org.eclipse.jetty.server.handler.ContextHandler entry it is expecting.

解决此问题的最佳方法是在部署/初始化期间不要有相互依赖的单独的Web应用程序(这在Servlet规范范围之外).按需(而不是在启动时)初始化/main_app/war/网络应用程序.

The best way to fix this is to not have separate webapps that depend on each other during deploy/init (that is out of scope for the servlet spec). Make the /main_app/war/ webapp init on demand, not on startup.

现在回到您的特定问题...

Now back to your specific problem ...

重要提示:请勿直接运行/编辑/运行/配置 $ {jetty.home} 目录.

Important: do not work / edit / run / configure the ${jetty.home} directory directly.

$ {jetty.base} 目录的存在是有原因的,使用它,这样做会更快乐.

The ${jetty.base} directory exists for a reason, use it, you'll be much happier when you do.

http://www.eclipse.org/jetty/documentation/current/startup.html

对于那些对装载顺序敏感的事情,请不要将 deploy 模块与这些工件一起使用.(将 deploy 模块用于您拥有的与加载顺序无关的其他Web应用程序是安全的)

For those things that are load order sensitive, do not use the deploy module with those artifacts. (its safe to use the deploy module for other webapps you have that don't have load order dependencies)

要完成此操作,我们将配置一个 $ {jetty.base} 目录以在启动时使用自定义xml文件,以及一个/special/目录用于这些依赖于加载顺序的 WebAppContexts ,请确保这些上下文不是 加载的,并由 deploy 模块进行管理.

To accomplish this, we'll configure a ${jetty.base} directory to use a custom xml file on startup, along with a /special/ directory for these load order dependent WebAppContexts, making sure that these contexts are not loaded, and managed by the deploy module.

$ cd my-jetty-base
$ mkdir etc
$ gvim etc/special-deploy.xml
$ echo "etc/special-deploy.xml" >> start.ini
$ ls -F
etc/  special/  start.ini  webapps
$ ls -F special/ 
main.war  security.war
$ cat start.ini
--module=http
jetty.port=8080
--module=deploy
etc/special-deploy.xml

special-deploy.xml 看起来像这样...

The special-deploy.xml looks like this ...

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

<!-- =============================================================== -->
<!-- Add Load Order Dependant Webapps                                -->
<!-- =============================================================== -->
<Configure id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">

  <Call name="addHandler">
    <Arg>
      <New class="org.eclipse.jetty.webapp.WebAppContext">
       <Set name="contextPath">/security</Set>
       <Set name="war"><SystemProperty name="jetty.base"/>/special/security.war</Set>
       <Call name="addAliasCheck">
         <Arg>
          <New class="org.eclipse.jetty.server.handler.ContextHandler$ApprovePathPrefixAliases"/>
         </Arg>
       </Call>
     </New>
    </Arg>
  </Call>

  <Call name="addHandler">
    <Arg>
      <New class="org.eclipse.jetty.webapp.WebAppContext">
       <Set name="contextPath">/</Set>
       <Set name="war"><SystemProperty name="jetty.base"/>/special/main.war</Set>
       <Call name="addAliasCheck">
         <Arg>
          <New class="org.eclipse.jetty.server.handler.ContextHandler$ApprovePathPrefixAliases"/>
         </Arg>
       </Call>
     </New>
    </Arg>
  </Call>

</Configure>

运行时,您将看到以下内容...

When you run you'll see the following ...

$ java -jar /path/to/jetty-distribution-9.2.10.v20150310/start.jar 
2015-04-29 12:18:55.929:INFO::main: Logging initialized @275ms
2015-04-29 12:18:56.093:WARN:oejsh.ContextHandler:main: ApprovePathPrefixAliases is not safe for production
2015-04-29 12:18:56.094:WARN:oejsh.ContextHandler:main: ApprovePathPrefixAliases is not safe for production
2015-04-29 12:18:56.097:INFO:oejs.Server:main: jetty-9.2.10.v20150310
2015-04-29 12:18:56.150:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /security, did not find org.eclipse.jetty.jsp.JettyJspServlet
2015-04-29 12:18:56.166:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@751d30f6{/security,file:/tmp/jetty-0.0.0.0-8080-security.war-_security-any-3863723758166154575.dir/webapp/,AVAILABLE}{/home/joakim/examples/load-order-example/special/security.war}
2015-04-29 12:18:56.181:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2015-04-29 12:18:56.183:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@4f79a28b{/,file:/tmp/jetty-0.0.0.0-8080-main.war-_-any-2704851460101920295.dir/webapp/,AVAILABLE}{/home/joakim/examples/load-order-example/special/main.war}
2015-04-29 12:18:56.184:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/joakim/examples/load-order-example/webapps/] at interval 1
2015-04-29 12:18:56.195:INFO:oejs.ServerConnector:main: Started ServerConnector@4ef6d773{HTTP/1.1}{0.0.0.0:8080}
2015-04-29 12:18:56.196:INFO:oejs.Server:main: Started @542ms
^C2015-04-29 12:19:09.594:INFO:oejs.ServerConnector:Thread-0: Stopped ServerConnector@4ef6d773{HTTP/1.1}{0.0.0.0:8080}
2015-04-29 12:19:09.599:INFO:oejsh.ContextHandler:Thread-0: Stopped o.e.j.w.WebAppContext@4f79a28b{/,file:/tmp/jetty-0.0.0.0-8080-main.war-_-any-2704851460101920295.dir/webapp/,UNAVAILABLE}{/home/joakim/examples/load-order-example/special/main.war}
2015-04-29 12:19:09.602:INFO:oejsh.ContextHandler:Thread-0: Stopped o.e.j.w.WebAppContext@751d30f6{/security,file:/tmp/jetty-0.0.0.0-8080-security.war-_security-any-3863723758166154575.dir/webapp/,UNAVAILABLE}{/home/joakim/examples/load-order-example/special/security.war}

这篇关于在码头定义webapp加载顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆