简体   繁体   English

如何在JBoss 7上使用外部jar?

[英]How can I use the external jars on JBoss 7?

Now I can load jars which is under the EAR/lib. 现在我可以加载EAR / lib下的jar。 But I want to put the jars to a common path, for other application to use. 但是我想把罐子放到一个共同的路径上,供其他应用程序使用。 I found that jboss-deployment-structure.xml file's tag can do this. 我发现jboss-deployment-structure.xml文件的标签可以做到这一点。 But it doesn't work. 但它不起作用。 I got the ClassNotFound exception. 我得到了ClassNotFound异常。 I don't know why? 我不知道为什么?

<deployment>
   <resources>
        <resource-root path="/common/test.jar" />
   </resources>
 </deployment>

One way of using global libraries in different applications can be reached by making them available as modules. 可以通过将它们作为模块使用来实现在不同应用程序中使用全局库的一种方法。 Therefor, extend the modules by the library you are providing as a server provider. 因此,通过您作为服务器提供商提供的库扩展模块。

Example: To make your test.jar available to all applications, create a folder with the modules name and a main subdirectory (eg modules/commons/test/main ). 示例:要使test.jar对所有应用程序可用,请创建一个包含模块名称和main子目录的文件夹(例如modules/commons/test/main )。

Place your library there and a module description file with the name module.xml . 将库放在那里,使用名为module.xml的模块描述文件。 Example content: 示例内容:

<module xmlns="urn:jboss:module:1.0" name="commons.test">
    <resources>
        <resource-root path="test.jar"/>
    </resources>
</module>

Now the library is available to all applications. 现在,该库可供所有应用程序使用。 To get access to the module, your application has to define the dependency in the manifest. 要访问该模块,您的应用程序必须在清单中定义依赖项。

Applications MANIFEST.MF : 应用程序MANIFEST.MF


Dependencies: commons.test

This can be also done by maven during build time. 这也可以在构建期间由maven完成。 Check https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7 for details 查看https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7了解详情

Please note that you're modifying the server itself. 请注意,您正在修改服务器本身。 All applications using your module are depending on it. 使用您的模块的所有应用程序都依赖于它。 A application with a dependency to the module commons.test wont be deployed on a server which does not have this module provided. 具有依赖于模块commons.test应用程序将不会部署在未​​提供此模块的服务器上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM