Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the external jars on JBoss 7?

Tags:

jboss7.x

Now I can load jars which is under the EAR/lib. 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. But it doesn't work. I got the ClassNotFound exception. I don't know why?

<deployment>
   <resources>
        <resource-root path="/common/test.jar" />
   </resources>
 </deployment>
like image 459
zhanglan Avatar asked Mar 12 '12 06:03

zhanglan


People also ask

Can jar be deployed in JBoss?

It's possible to deploy EJB-jar files directly in Jboss (jar extension), if they follow the EJB packaging model (you don't need to place it in an ear necessarily).

What is JBoss modules jar?

JBoss Modules is designed to work with any existing library or application without changes, and its simple naming and resolution strategy is what makes that possible. Unlike OSGi, JBoss Modules does not implement a container; rather, it is a thin bootstrap wrapper for executing an application in a modular environment.

Where we can put Jarfile?

The best way is to add the jar to your project is as follows: Create a folder called lib in your project folder. copy all the jar files you need to this folder . Refresh your project in eclipse.


1 Answers

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 (e.g. modules/commons/test/main).

Place your library there and a module description file with the name 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:


Dependencies: commons.test

This can be also done by maven during build time. Check https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7 for details

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.

like image 147
Oliver Probst Avatar answered Jan 03 '23 12:01

Oliver Probst