驻留在 jar 中的 EJB 的注入问题
我有一些关于 EJB 注入的问题,但我无法在任何地方找到解决方案。
我的情况如下:我有一个 EAR 文件,其中包含一个 WAR 和几个 JAR,所有这些都列在 application.xml 文件中。这部分一切工作正常。 当我尝试添加我们所谓的“插件系统”时,问题就出现了。 我有一个 JAR,里面有一些 .xhtml 页面、支持 bean 和 EJB。如果需要,此 JAR 会插入 EAR 内的特定目录(我们称之为“插件”),并在启动时从应用程序中检测到。
当检测到 JAR 时,它的路径将被添加到 WAR 类加载器中,因此所有页面和支持 bean 都会被毫无问题地检测到。不起作用的是 EJB 的注入(我尝试使用符号 @EJB、@Inject、查找...)。我无法注入 JAR 插件内的任何 EJB。
我的猜测是,应用程序服务器将 JAR 视为简单的库模块,并且不会在其中查找任何 EJB,因此它们位于 JAR 内,但不能从应用程序中使用。
我的问题是:有办法让它发挥作用吗?我尝试在 EAR 的 MANIFEST.MF 中添加 JAR,但没有任何改变...
我使用的应用程序服务器是 glassfish 3.0。关于 application.xml:其中没有关于 JAR 的参考,这些 JAR 是我所谓的“插件系统”的一部分。这是因为我在应用程序服务器中部署(或重新启动)应用程序时检测到它们,因此它们可能位于也可能不在系统内部,并且在系统启动之前我并不真正知道这一点。 每个插件 JAR 都是页面和功能的“集合”,可以动态添加或从系统中删除(不太像真正的插件系统)。 我的 EAR 结构如下:
MyApp.EAR
- META-INF
- lib
- 插件
- plugin1.JAR
- app.WARlogic1.JARlogic2.JAR
- ,
- 位于
例如:在application.xml中我有app.WAR,logic1.JAR和logic2.JAR的引用(它们总是在系统内部) 启动应用程序会在“plugins”文件夹中查找要添加到系统的任何插件(特定 JAR)。
我希望我已经更清楚我正在尝试做什么......
I have some problems regarding the EJB injection and I haven't been able to find a solution anywhere.
My situation is the following: I have an EAR file that includes a WAR and several JARs, all listed in the application.xml file. All is working fine for this part.
The problems come out when I try to add what we can call a “plugin system”.
I have a JAR with inside some .xhtml pages, backing beans and EJBs. This JAR, if needed, is inserted inside the EAR in a specific directory (let's call it “plugins”) and is detected from the application at startup.
When the JAR is detected it's path is added to the WAR class loader so all the pages and the backing bean are detected without problems. What is not working is the injection of the EJBs (I tried to use the notation @EJB, @Inject, the lookup...). I can't inject any of the EJBs that is inside the JAR plugin.
My guess is that the application server treats the JAR as a simple library module and doesn't look for any EJB inside it, so they are inside the JAR but not usable from the application.
My question is: there's a way of having this working? I tried to add the JAR in the EAR's MANIFEST.MF but nothing changed...
the application server i'm using is glassfish 3.0. About the application.xml: there's no reference in it about the JARs that are part of what i called "plugin system". This because i detect them when i deploy (or i restart) the application in the application server, so they may or may not be inside the system and i don't really know that before the system is started.
Each plugin JAR is a "collection" of pages and functionalities that can be added or removed from the system dynamically (more less like a real plugin system).
My EAR structure is the following:
MyApp.EAR
- META-INF
- lib
- plugins
- plugin1.JAR
- app.WAR
- logic1.JAR
- logic2.JAR
for example: in the application.xml i have the references for app.WAR, logic1.JAR and logic2.JAR (they are always inside the system), at startup the application looks inside the folder "plugins" for any plugin (specific JARs) to be added to the system.
I hope i've been more clear about what i'm trying to do...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 EJB 甚至没有在服务器的 JNDI 树中注册。您使用哪个应用程序服务器?您可以查看此 JNDI 树以查看 EJB 是否存在,但执行此操作的方法取决于特定的服务器。
您如何在 EAR application.xml 中声明包含 EJB 的 JAR?
应该是这样的:
Jar 应该位于 EAR 的“/lib”目录中。
我希望这有帮助。
It seems that the EJB are not even registered in the JNDI tree of the server. Which application server are you using? You can have a look to this JNDI tree to see if the EJBs are there, but the way to do this depends on the specific server.
How are you declaring the JAR that contains the EJBs in the EAR application.xml?
It should be someting lide this:
The Jar should be in a the "/lib" directory of the EAR.
I hope this helps.