gpt4 book ai didi

java - WAR Web 应用程序重新部署依赖项

转载 作者:行者123 更新时间:2023-12-02 04:42:54 26 4
gpt4 key购买 nike

我是 Java 新手。部署网络应用程序时遇到一些问题。

我有一个部署在 Glassfish (4.1) 上的 EJB 项目。我还有第二个 JSF WEB 应用程序,它部署到同一台服务器上。尽管我这样做是考虑到它将被部署到一个单独的服务器,所以它创建了自己的 InitialContext 等来访问 EJB。

Web 应用程序依赖于 EJB 项目。依赖项在 Web 应用程序的 pom 中声明。部署 Web 应用程序时,由于某种原因,它还会尝试部署其他项目中的 EJB。由于 EJB 已单独部署在此服务器上,因此会失败,并出现诸如 javax.naming.NameAlreadyBoundException 之类的错误。

如何解决这个问题,以便不会尝试部署来自 WEB 应用程序的 EJB 依赖项?

更新:解决方案需要重构,因此不再依赖 EJB。

            Original        

Project A WEB app
________________ ____________
| + EJBs |<------| WEB stuff |
| + Domain cl. | ------------
| + Remote intf. |
----------------

===========================================
Refactored

_______ ____________
| EJBs |----->| Domain cl. |
------- ------------
| ^
| |
| |
v | WEB app
______________ ____________
| Remote intf. | <---| Web stuff |
-------------- ------------

最佳答案

您可以为依赖项提供 providedscope:

<dependency>
<groupId>group.id</groupId>
<artifactId>artifact.some.id</artifactId>
<version>1.0</version>
<type>ear</type>
<scope>provided</scope>
</dependency>

这意味着在运行时,依赖项将由容器提供。

参见 Maven 文档:

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

关于java - WAR Web 应用程序重新部署依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29965005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com