Custom Library Management for specific JBoss Server Instance

In one of our previous post, we have discussed about the Directory Structure of JBoss. There is a specific directory called ‘lib‘ in each JBoss Server Instance (JBoss Server Profile).

jbs_dir_focused

The ‘lib‘ directory consists of JAR files which is specific to given JBoss Server Profile (or Instance). It is very convenient to place all the libraries related to given profile. But the only problem with this is, when we add up huge number of JAR files in this folder, it becomes hard for us to manage library files.

Consider I have an e-commerce application I deployed on JBoss Profile named ‘default‘. I have multiple modules under this application such as,

  • Sales
  • Marketing
  • Order Management
  • CRM

and so on.

And I have many supporting 3rd party libraries for each of these modules. What I would do as a laymen, I would place all the libraries under the ‘lib‘ directory. But, this will cause the Spaghetti Artifacts problem. Means, libraries of all modules are placed under one directory. Everything’s together… Mixed… like Spaghetti!!! This becomes hard to manage if I want to keep track of all the libraries I have added for each modules.

Well, not to be alarmed!!! We have a luxury in JBoss to manage libraries under given profile more custom way. Following are the steps:

Step-1: Go to ‘lib‘ directory under your JBoss Server Profile (here default).

lib_1

Step-2: Create module wise directories under lib.

lib_2

Step-3: Place your module specific libraries under each module directory created.

lib_3

Ok, we’re good so far. We have placed segregated JAR files module wise for each modules. But, the story doesn’t end here. JBoss will not consider all the .jar files under lib directory recursively unlike deploy folder does unless you ask JBoss to consider these jar file explicitly in classpath. Well, for this configuration, follow the important Step-4.

Step-4:  Go to jboss-service.xml file available in conf folder at $JBOSS_HOME\server\default\conf. The classpath of these custom modules libraries are configured in this file as following:

lib_conf

Note the classpath entries added for each module (line no. 19-22) in above file. Here, the library classpath already exists for lib directory (line no. 15). Here, the JBoss Property ${jboss.server.lib.url} consists of path lib folder of ‘this‘ server instance.

We just have extended the classpath further by adding path of sub-directory under this directory by padding module name with this JBoss Property. 

After this configuration, you are required to restart the instance. This is it!!!

Yeaahh, Life was never been so easy!!! :-)