Glassfish - 部署两个相互依赖的 JAR
我是 Java EE 的新手,所以也许这是一个虚拟问题。但我正在将 WAR 和包含 EJB 的 JAR 部署到 Glassfish 3.1。服务器。 WAR 引用了 JAR 文件中的 EJB 之一。是否必须将 EJB JAR 包含在 WAR 文件的 lib 目录中才能使其正常工作?由于 WAR 和 JAR 将在同一应用程序服务器上运行,因此我希望不需要处理这些依赖项。但是,当我部署 WAR 时,如果它不包含 EJB JAR(即使 EJB JAR 已部署在应用程序服务器上),我会收到 java.lang.NoClassDefFoundError
。
I'm a newcomer to Java EE so perhaps this is a dummy question. But I'm deploying a WAR and a JAR containing EJBs to a Glassfish 3.1. server. WAR has a reference to one of the EJBs in the JAR file. Is it mandatory to include the EJB JAR in the WAR file's lib
directory in order to make this work? Since both WAR and JAR will be running on the same app server, I was hoping that I wouldn't need to take care of these dependencies. However, I am getting a java.lang.NoClassDefFoundError
when I deploy the WAR if it doesn't include the EJB JAR (even though the EJB JAR is already deployed on the app server).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java EE 的基石之一是不同的组件可以在不共享命名空间的容器中运行,即使这些组件可能运行在同一个 JVM 中。如果您有需要共享命名空间的模块,则需要将它们捆绑到 EAR(Java EE 6 之前的版本)中或组合成单个 WAR(Java EE 6 为需要利用 EJB 的 Web 应用程序建立的特殊情况) 。
这与熟悉 Java SE 开发的人们所“了解”的情况相比是一个重大变化。对于大多数 Java SE 程序来说,容器就是 JVM 进程。
因此,您的问题的答案是:“不。您不需要将 EJB jar 放在 WAR 文件的 lib 目录中。您可以创建一个包含两个存档的 EAR 文件。”
这可能会为您澄清情况......
One of the cornerstones of Java EE is the notion that different components can run in containers which do not share a namespace, even though the components may be running in the same JVM. If you have modules that need to share a namespace, they need to be bundled into an EAR (prior to Java EE 6) or combined into a single WAR (a special case established by Java EE 6 for web applications that need to leverage EJBs).
This is a significant change from what folks familiar with Java SE development "know". For most Java SE programs, the container is the JVM process.
So, the answer to your question is, "No. You do not need to put the EJB jar in the lib directory of the WAR file. You could create an EAR file that would contain BOTH archives."
This may clarify the situation for you...
您是否尝试过将 WAR 和 JAR 文件一起打包成 EAR 文件? EAR 文件可以有一个 lib 目录,您可以在其中放置要加载到企业应用程序的类路径 FBO 上的 JAR 文件。
这应该可以解决您的类加载器问题。
Have you tried packaging the WAR and JAR file together into an EAR file? The EAR file can have a lib directory where you can put JAR files to be loaded on the classpath FBO of the enterprise application.
This should solve your classloader issue.