How to load jars residing over NFS in JBossAS7 classpath ? --reference

In this article we will discuss how can we load jars residing over NFS in JBoss AS-7 classpath. In some development environment, when there are multiple jars and properties files are being used by multiple servers, it is good to put all of them in a central repository, so that if the files (jar/properties files/xmls) are modified, all the servers will pickup the latest version and there will be less overhead related to copying the latest versions to individual servers

NFS allows a user on a client computer to access files over a network in a manner similar to how local storage is accessed. I installed NFS using below link :

Remote_Disk_Access_with_NFS#Installing_NFS

As JBoss AS-7 has introduced a module structure to load your custom jars. One can quickly create a custom module and put the required jars in them, with appropriate entries in module.xml . But in this case we would be needing an additional module directory, which would be residing over NFS server and we would map this to our local (client) server.

Step-1: Modify standalone.sh and add a separate module directory. To do this navigate to $JBOSS_HOME/bin and edit the file.

Search for keyword “module” and it should look like below :

..

if [ "x$JBOSS_MODULEPATH" = "x" ]; then

    JBOSS_MODULEPATH="$JBOSS_HOME/modules"

fi

..

Edit the above section of your “standalone.sh” script and then add the “:” separated path of your module directories as following

..

JBOSS_MODULEPATH=/mnt/nfs:$JBOSS_HOME/modules



#if [ "x$JBOSS_MODULEPATH" = "x" ]; then

  #  JBOSS_MODULEPATH="$JBOSS_HOME/modules"

#fi

..

 

Here /mnt/nfs/ is the directory, where our new module directory would be residing.

Step-2 : On the shared mount create below directory structure :

..

/mnt/nfs/

├── aaa

   └── bbb

       └── ccc

           └── main

               ├── module.xml

          ├── utility_JAR.jar



..

 

where

module.xml :

..



<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="aaa.bbb.ccc">

   <resources>

       <resource-root path="utility_JAR.jar"/>

   </resources>

</module>



..

Step-3 : Now lets create a simple application which would be using utility_JAR.jar (ClassLoaderTestWAR.war). The war file will have below structure :”

..

ClassLoaderTestWAR.war/

├── index.jsp

├── WEB-INF

   ├── jboss-deployment-structure.xml

   ├── web.xml

..

 

Where :

index.jsp :

..

<html>

     <head><title>ClassLoader Demo</title></head>

     <body bgcolor="maroon" text="white">

            <center>

                    <h1>Class Loader Demo..</h1>



<%

       aaa.bbb.TestUtility utility=new aaa.bbb.TestUtility();

       String whichClassLoader=utility.sayWhichClassLoader();

       System.out.println("\n\n\t -----> "+whichClassLoader);

       out.println("<h1>"+whichClassLoader+"</h1>");

%>



      </body>

</html>

..

 

jboss-deployment-structure.xml :

..



<?xml version="1.0" encoding="UTF-8"?>

<jboss-deployment-structure>

 <deployment>

   <dependencies>

       <module name="aaa.bbb.ccc" />

   </dependencies>

 </deployment>

</jboss-deployment-structure>



..

web.xml :

..



<web-app>

   <welcome-file-list>

       <welcome-file>index.jsp</welcome-file>

   </welcome-file-list>

</web-app>



..

Step-4 : Now deploy the application and start the JBoss AS-7 server.

Step-5 : Access the application using : http://localhost:8080/ClassLoaderTestWAR

You will see something like below :

How to load jars residing over NFS in JBossAS7 classpath ? --reference

If the above output comes that means the jar was loaded from our new module directory, which resides over NFS.

原文地址:http://middlewaremagic.com/jboss/?p=2561

你可能感兴趣的:(classpath)