【问题标题】:how to use "war.context" in Configuration file of Play Framework ?如何在 Play Framework 的配置文件中使用“war.context”?
【发布时间】:2010-12-05 10:10:53
【问题描述】:

如何在 Play Framework 的配置文件中使用“war.context”?

【问题讨论】:

    标签: playframework


    【解决方案1】:

    查看 Google 网上论坛上的此主题,了解您所要求的内容。

    http://groups.google.com/group/play-framework/browse_thread/thread/b4783c821fd29898?pli=1

    本质上,它在说什么。

    在您的 application.conf 文件中,您设置一个属性,例如

    war.context=/MyAppName
    

    然后,在您的路由文件中,您将其设置为以下列方式包含您的 WAR 上下文

    # Set context name 
    %{ ctx = play.configuration.getProperty('war.context', '') }% 
    
    # Routes 
    # This file defines all application routes (Higher priority routes first) 
    # ~~~~ 
    # Home page 
    GET     ${ctx}/                                      Application.index 
    # Map static resources from the /app/public folder to the /public path 
    GET     ${ctx}/public/                               staticDir:public 
    # Catch all 
    *       ${ctx}/{controller}/{action}                 {controller}.{action} 
    

    因此,您可以看到,无论您在 war.context 中放置什么,然后您都可以将其放入您的路线以选择正确的路径。

    【讨论】:

    • 你确定这是 play 1.1 的推荐方式吗?
    • 在灯塔上提出了一张罚单(这仅在 1.1 之后才存在),纪尧姆指出上述线程作为问题的答案。
    • 我试了一下,我得到了空页 tomcat 日志:信息:部署 Web 应用程序存档 ROOT.war 2011 年 6 月 1 日上午 4:33:29 org.apache.catalina.loader.WebappClassLoader validateJarFile 信息: validateJarFile(/home/ganshla2/jvm/apache-tomcat-6.0.14/domains/ganshla-ganshla.com/ROOT/WEB-INF/lib/geronimo-servlet_2.5_spec-1.2.jar) - jar 未加载。请参阅 Servlet 规范 2.3,第 9.7.2 节。违规类:javax/servlet/Servlet.class 04:33:36,470 INFO ~ 开始 /home/ganshla2/jvm/apache-tomcat-6.0.14/domains/ganshla-ganshla.com/ROOT/WEB-INF/application 04: 33:37,265 INFO ~ 应用程序已预编译
    • 从您的日志中您可以看到它实际上正在部署到 ROOT 上下文。如果不使用Play自带的服务器,还需要在Tomcat的server.xml中指定上下文不同。
    猜你喜欢
    • 2015-05-13
    • 1970-01-01
    • 2018-09-20
    • 2014-03-18
    • 2013-07-27
    • 1970-01-01
    • 2015-04-02
    • 2016-08-10
    • 2013-04-20
    相关资源
    最近更新 更多