在应用程序 javaee5 中加载共享类
我正在尝试在 java ee 5 应用程序中加载一些我耳中所有 Web 应用程序通用的类。
我尝试通过将类(而不是 jar)放入 a) 名为“lib”的目录
b) 也在 application.xml 中指定
<module><java>lib/common.jar</java></module>
,并且通过选项 a 或 b 都没有成功
,但是当我将类打包到 common.jar 中时,我能够通过方法加载类 b)
- 执行这两项操作方法需要对类进行震动吗?
- 通过上述两种方法提供类有什么区别?为什么看起来有两种方法来指定加载公共类?
I am trying to load some classes that are common to all the web applications of my ear in a java ee 5 application.
I tried to do this by putting the classes (not jar) in
a) directory called "lib"
b) also specifying in application.xml's
<module><java>lib/common.jar</java></module>
and was not successful by either option a or b
but when I jarred the classes into common.jar, I was able to load the classes by method b)
- Do both these method need the classes to be jarred ?
- what is the difference between providing the classes via the above 2 methods ? why does it seem like there are two ways to specify loading common classes ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这里指的是哪个应用程序服务器,以及 common.jar 文件的性质。现在,我假设应用程序服务器是任何 Java EE 5 容器,并且 common.jar 文件是实用程序 jar(而不是 EJB 或类似模块)。
Java EE 5 平台规范实际上定义了容器提供库支持的方式:
这并不意味着方法 B 不正确,它是用于 像 JBoss 4 这样的应用程序服务器,不支持 application.xml 中的库目录元素。我相信,Glassfish 也支持 lib 目录概念,但没有相应的库目录元素。
回到问题,将类单独放置在 EAR 文件的目录中似乎仅在 WebLogic Server 中通过 APP-INF\classes 结构受支持(不用说,这不是平台标准)。因此,建议将公共类打包并使用应用程序服务器支持的机制使这些公共类可供应用程序中的其他模块使用。
I'm not sure which application server is being referred to here, and the nature of the common.jar file. For now, I'll assume that the application server is any Java EE 5 container, and that the common.jar file is a utility jar (and not an EJB or similar module).
The Java EE 5 Platform Specification actually defines the manner in which library support is to be provided by containers:
This does not mean that method B is incorrect, it is the one to be used for application servers like JBoss 4, that did not support the library-directory element in application.xml. I believe, Glassfish also supports the lib directory concept without a corresponding library-directory element.
Coming back to the question, placing classes alone in a directory in the EAR file appears to be supported only in WebLogic Server via the APP-INF\classes structure (needless to say, this is not a platform standard). Hence, it is recommended to jar the common classes and use the application server supported mechanism to make these common classes available to other modules in the application.