【问题标题】:Using the context-root from glassfish-web.xml in GlassFish 3在 GlassFish 3 中使用 glassfish-web.xml 的上下文根
【发布时间】:2013-04-19 10:34:15
【问题描述】:

我们最近切换到 Glassfish 3.1.2.2 并将几个 Web 应用程序打包为 war 文件。有时,这些应用程序所需的上下文根与文件名不同。

当我们使用 Weblogic 时,我们通过像这样在 weblogic.xml 中声明上下文根来实现这一点

<context-root>path/to/our/App</context-root>

我们注意到 glassfish-web.xml 中存在相同的标签。但是无论我们在那里定义什么,服务器总是将文件名确定为上下文根。

现在我们在 asadmin 实用程序中找到选项 --contextroot 允许我们在部署时覆盖文件名,但我们更愿意直接在存档本身中定义它,以便最终部署它的人不需要知道所需的上下文根。

有什么办法可以做到吗?

【问题讨论】:

    标签: glassfish war asadmin contextroot


    【解决方案1】:

    通常这应该与如下所示的 glassfish-web.xml 一起使用:

    <!DOCTYPE glassfish-web-app PUBLIC 
        "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN"
        "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
    <glassfish-web-app>
        <context-root>/path/to/App</context-root>
    </glassfish-web-app>
    

    但在这里,您的任务似乎需要一个名为 sun-web.xml 的文件。

    这是一个例子:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sun-web-app PUBLIC 
         "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN"   
         "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
    <sun-web-app error-url="">
        <context-root>/path/to/our/App</context-root>
    </sun-web-app>
    

    【讨论】:

    • 这很奇怪(而且有点尴尬)我们确实设置了该标签(尽管在 glassfish-web.xml 中,因为该文件已在 GF 3.1 中重命名)但没有注意到我们在我们的 maven 配置中覆盖了它文件名作为上下文根显式传递,覆盖 glassfish-web.xml 中的定义。你当然是正确的:)
    • 即使我同时配置了 glassfish-web.xml 和 sun-web.xml,使用 java ee war 部署的 glassfish 3.1.2.2 对我也不起作用。只有 tha asadmin deploy 参数 --contextroot=/ 有帮助。但我期待为这个主题找到正确的配置。
    • 我做了更多的实验,最后的解决方案是只修改 glassfish-web.xml。如果我只将 context-root 参数添加到 glassfish-web.xml 而不是 sun-web.xml,那么结果就是预期的。
    【解决方案2】:

    在 GlassFish 3 和 GlassFish 4 中,Web 应用程序的配置是通过 glassfish-web.xml 完成的。在您的情况下,所需的配置文件如下所示:

    <!DOCTYPE glassfish-web-app PUBLIC 
        "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN"
        "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
    <glassfish-web-app>
        <context-root>/path/to/our/App</context-root>
    </glassfish-web-app>
    

    您可以在Oracle GlassFish Server 应用程序部署指南GlassFish Server 部署描述符文件 部分找到更多详细信息。此文档的在线版本可以在http://docs.oracle.com/cd/E18930_01/html/821-2417/ 找到。

    【讨论】:

    • 是的,我遇到了类似的问题。 sun-web.xml 对上下文根没有影响。我改为使用glassfish-web.xml。它有效。
    猜你喜欢
    • 1970-01-01
    • 2013-10-03
    • 2014-04-17
    • 1970-01-01
    • 2013-05-05
    • 2018-09-16
    • 2012-11-25
    • 2011-07-03
    • 1970-01-01
    相关资源
    最近更新 更多