java Glassfish 3.1.2.2 上 Web 应用程序的上下文路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11853901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Context path for web application on Glassfish 3.1.2.2
提问by PhilDin
I'm trying to find a way to explicitly specify the context path of a web application being deployed to Glassfish 3.1.2.2 but I've had no luck so far. Can anyone provide guidance on this? The background to this is below:
我试图找到一种方法来明确指定部署到 Glassfish 3.1.2.2 的 Web 应用程序的上下文路径,但到目前为止我没有运气。任何人都可以提供这方面的指导吗?其背景如下:
I have a web application that consists of two separate Netbeans (7.0) projects. The first is a web service and is called FooWS. The second is a user facing web application which uses the FooWS webservice. It's called FooApp.
我有一个由两个单独的 Netbeans (7.0) 项目组成的 Web 应用程序。第一个是 Web 服务,称为 FooWS。第二个是面向用户的 Web 应用程序,它使用 FooWS Web 服务。它被称为 FooApp。
I've recently upgraded glassfish to 3.1.2.2 in the hope of resolving some other issue and now when I deploy the FooWS app, it deploys successfully but with the context path /web rather than /FooWS. This is not something I would particularly care about except that when I try to deploy FooApp, glassfish also tries to deploy that to /web leading to the following error:
我最近将 glassfish 升级到 3.1.2.2,希望能解决其他一些问题,现在当我部署 FooWS 应用程序时,它部署成功但使用上下文路径 /web 而不是 /FooWS。这不是我特别关心的事情,除了当我尝试部署 FooApp 时,glassfish 还尝试将其部署到 /web 导致以下错误:
SEVERE: Exception while loading the app : java.lang.Exception: WEB0113: Virtual server [server] already has a web module [FooWS] loaded at [/web]; therefore web module [FooApp] cannot be loaded at this context path on this virtual server.
严重:加载应用程序时出现异常:java.lang.Exception:WEB0113:虚拟服务器 [server] 已经在 [/web] 加载了一个 web 模块 [FooWS];因此无法在此虚拟服务器上的此上下文路径中加载 Web 模块 [FooApp]。
The web.xml for FooApp looks as follows:
FooApp 的 web.xml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>defaultWebRootId</param-name>
<param-value>2631</param-value>
</context-param>
<listener>
<listener-class>com.foo.service.AppInitialiser</listener-class>
</listener>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
The configuration for FooWS is similar. Neither contains any mention of the application context so my expectation is that it should use /FooWS rather than default to /web.
FooWS 的配置类似。两者都没有提到应用程序上下文,所以我的期望是它应该使用 /FooWS 而不是默认为 /web。
The obvious solution would seem to be to override the context path in the web.xml but I can't find any way of doing this. Any suggestions?
显而易见的解决方案似乎是覆盖 web.xml 中的上下文路径,但我找不到任何方法来做到这一点。有什么建议?
Just some follow up, I accidentally changed the context path to /FooW. This time it deployed as expected to /FooW. Changing it back if /FooWS causes the old behaviour to return, that is, it deploys again to /web. It seems like I have a workaround for the moment.
只是一些跟进,我不小心将上下文路径更改为 /FooW。这次它按预期部署到 /FooW。如果 /FooWS 导致旧行为返回,则将其改回,即再次部署到 /web。目前看来我有一个解决方法。
For the benefit of anyone following this, I got the same behaviour with 3.1.2. I have now returned to 3.1 (b43) and it behaves as expected.
为了任何人的利益,我在 3.1.2 中得到了相同的行为。我现在已经返回到 3.1 (b43) 并且它的行为符合预期。
回答by Alf
Add a glassfish-web.xml file in the same folder as web.xml
在与 web.xml 相同的文件夹中添加 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 error-url="">
<context-root>/FooWS</context-root>
</glassfish-web-app>