在 Tomcat 中的 war 文件之间共享 Java 类?
我使用 Tomcat 7 作为 servlet 容器,并且有两个 war 文件(Eclipse 中的两个项目)。问题是,我想在两个部署的 war 文件之间共享类。 但据我所知,Tomcat / Servlet 规范是不可能的。两个部署的 Web 应用程序似乎是相互隔离的。
所以我读到,我是一个新手,从 JBoss 作为应用程序服务器,我可以在其中部署ear文件(这样我可以将多个war文件放入其中),然后我可以在它们之间共享类?
所以我的问题是:你同意我的说法吗?JBoss 可以做到这一点吗?我是否必须进行更改,或者我可以轻松地将两者放入 Ear 文件中并使用 JBoss 部署它并且它会起作用吗?
最好的问候,蒂姆。
I am using Tomcat 7 as a servlet container and I have two war files (two projects in Eclipse). The problem is, that I want to share classes between both deployed war files.
But this is not possible with Tomcat / Servlet specifications as far as I know. Both deployed web applications seems to be are isolated from each other.
So I read, I am a newbie, from JBoss as an application server in which I can deploy ear files (so I can put multiple war files into it) and then I can share classes between them?
So my question: Do you agree with my statement, is it possible to do this with JBoss? And do I have to make changes or can I put easily both in an ear file and deploy it with JBoss and it will work?
Best Regards, Tim.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有 2 个简单的选择。两者都要求您在单独的项目 (JAR) 中定义共享类,我们将其称为SHARED。现在,当涉及到部署时,您有 2 个选择:
如果您选择选项 #1,重要的是要了解相同的类在 WebApp 类加载器(Tomcat 系统类加载器)之间共享,因此只有当您想在不同的 WebApp 之间共享状态(例如单例)时,您才需要使用此选项。
顺便说一句:屏幕截图是使用 Eclipse 3.6 + WTP 制作的...
There are 2 easy options. Both require you to define the shared classes in a separate project (JAR), let's call it SHARED. Now, when it comes to deployment you have 2 options:
If you go with option #1 it is important to understand that the same classes are shared between the WebApp classloaders (Tomcat system classloader), so you'd go with this option only if you want to share state between different WebApps (e.g. Singletons).
BTW: The screenshot is made using Eclipse 3.6 + WTP...