是否可以在同一个部署路径下部署多个war个文件?
Is it possible to deploy multiple war files under the same deployment path?
假设我有:
foo.war
bar.war
我是否可以通过某种方式将它们部署到相同的部署路径?例如,要访问它:
war 文件的内容是否以某种方式合并?如何处理文件冲突(例如,假设它们都有一个 index.jsp
文件)?
提前致谢!
是与否。
我认为不可能以某种方式将它们合并到像 Tomcat 这样的 servlet 容器内的同一文件系统路径中(除非您要编写某种复杂、智能的脚本来这样做)。对于初学者来说,每个 .war 都有一个 WEB-INF/web.xml
文件,每个文件都将依赖其自身文件的内容来运行——哪个会赢?
但你可以想象...
- 部署到 2 个不同的上下文(或容器或主机),并使用某种负载均衡器(硬ware 或软ware)将一些请求路由到一个,另一个向对方提出要求。
- 使用 "overlay" 策略(例如 Maven Overlays)创建第二个(也是最终的).war,它是另一个 .war 的衍生和扩展文件
servlet 规范明确禁止这样做。已部署的 Web 应用程序可能没有相同或重叠的上下文根。来自 Servlet 3.0 规范,第 10.5 节:
Since the context path of an application determines the URL namespace of the contents of the Web application, Web containers must reject Web applications defining a context path that could cause potential conflicts in this URL namespace. This may occur, for example, by attempting to deploy a second Web application with the same context path.
假设我有:
foo.war
bar.war
我是否可以通过某种方式将它们部署到相同的部署路径?例如,要访问它:
war 文件的内容是否以某种方式合并?如何处理文件冲突(例如,假设它们都有一个 index.jsp
文件)?
提前致谢!
是与否。
我认为不可能以某种方式将它们合并到像 Tomcat 这样的 servlet 容器内的同一文件系统路径中(除非您要编写某种复杂、智能的脚本来这样做)。对于初学者来说,每个 .war 都有一个 WEB-INF/web.xml
文件,每个文件都将依赖其自身文件的内容来运行——哪个会赢?
但你可以想象...
- 部署到 2 个不同的上下文(或容器或主机),并使用某种负载均衡器(硬ware 或软ware)将一些请求路由到一个,另一个向对方提出要求。
- 使用 "overlay" 策略(例如 Maven Overlays)创建第二个(也是最终的).war,它是另一个 .war 的衍生和扩展文件
servlet 规范明确禁止这样做。已部署的 Web 应用程序可能没有相同或重叠的上下文根。来自 Servlet 3.0 规范,第 10.5 节:
Since the context path of an application determines the URL namespace of the contents of the Web application, Web containers must reject Web applications defining a context path that could cause potential conflicts in this URL namespace. This may occur, for example, by attempting to deploy a second Web application with the same context path.