从 EAR 项目中的 War 项目访问 EJB 项目中的类?
我正在创建一个基于 MDB 的项目和支持这些 MDB 的类。我还需要使用 ServletContextListener 与 MDB Universe 交互(详细信息如下),这意味着我需要一个 WAR 项目。
问题:ServletContextListener 如何访问 EJB 项目中的类?
项目组织(标准 Eclipse EAR 项目):
EAR 项目 里面有一些罐子 EJB项目 有一些 MDB 和 MDB 使用的许多其他类 战争项目 有ServletContextListener。
我为什么要这样做?我需要在项目启动时启动一个线程。该线程需要访问 MDB 也使用的一堆类。
注意:我知道我可以将这些通用类放入 EAR 项目中的 jar 中。如果有一种方法可以做到这一点,使得单个 Eclipse“调试为”->“在服务器上”那么这将构成一个很好的解决方案。无论提供什么解决方案,都需要支持服务器上的调试,并对所有类进行逐步调试。
注意 2:我可以告诉 Eclipse WAR 项目依赖于 EJB 项目,这会删除 Eclipse 错误标志,但 Eclipse 显示警告,表明部署的项目中不存在此依赖关系,这意味着我从 WAR 访问的类将失败在运行时实例化。
I am creating a project based on MDB's and classes supporting those MDB's. I also need to use a ServletContextListener to interact with the MDB universe (details below), meaning I need a WAR project.
Question: How can the ServletContextListener access a class in the EJB project?
Project organization (standard Eclipse EAR project):
EAR Project
has some jars in it
EJB Project
has some MDB's and lots of other classes used by MDB's
WAR Project
has ServletContextListener.
Why am I doing this? I need to start a thread when the project starts. This thread needs access to a bunch of the classes also used by the MDB's.
NOTE: I understand that I could put these common classes into a jar in the EAR project. If there is a way to do this such that a single eclipse "Debug As"->"On Server" then that would constitute a good solution. Whatever solution is provided needs to support that debug on server, with step debugging into all classes.
NOTE 2: I can tell Eclipse that the WAR project is dependent on the EJB project, which removes the Eclipse error flags, but eclipse shows a warning that this dependency will not exist in the deployed project, meaning my classes accessed from the WAR will fail to instantiate at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 Java EE 服务器上的“标准”部署(即:使用默认类加载器策略),WAR 类“可以看到”封闭 EAR 中的所有内容,并且 EAR 类优先。
您不是反过来做吗?这是 EAR 项目,需要在项目的“Properties -> Deployment Assembly”部分中包含您的 WAR 项目。
我想到的另一种可能性是,您可能正在尝试部署在非 Java EE 服务器上,例如 Tomcat,它不支持 EAR。这可能就是 Eclipse 说已部署的项目中不存在依赖项的原因。
With "standard" deployment on a Java EE server (meaning: with the default class loader policy), WAR classes "can see" everything that's in the enclosing EAR, and the EAR classes take precedence.
Aren't you doing it the other way around? It's the EAR project that needs to have your WAR project in the project's "Properties -> Deployment Assembly" section.
Another possibility that comes to mind is that maybe you're trying to deploy on a non-Java EE server, like Tomcat, which does not support EARs. This could be why Eclipse says that the dependency won't exist in the deployed project.