2 Replies Latest reply on Feb 11, 2010 1:20 PM by Gilles Compienne

    Classloaders: How to hide classes from the DefaultDomain?

    Gilles Compienne Newbie

      I have a jar that uses Infinispan (JBossCache's replacement) and I want to load it with the Infinispan libraries on JBoss AS 5.1.

       

      Now my problem is that JBoss AS 5.1 uses an older version of JGroups that seems to be incompatible.

       

      Also, I have seen simlar issues with other libraries where they use reflection to detect their versions. But this means that when they see the classes used by JBoss AS (via the DefaultDomain) then they sometimes mis-identify what version of a lib they are currently using.

       

      So I am looking at isolating my JAR file (and its internal libraries) by specifying the classloading constraints via the jboss-classloading.xml file.

       

      I am able to specify my new (separate) domain however I can't set the parent domain to be the "java" domain (i.e. java.* and nothing else).

       

      I tried to set it to "" or "null" but to no avail.

       

      And this means that currently everything loaded by the AS is made visible to the JAR (when ideally I want to specify what I will use from the AS and implicitely what I intend to provide myself...).

       

      <classloading domain="InfinispanCacheDomain" xmlns="urn:jboss:classloading:1.0"
                    import-all="false" parent-first="false" parent-domain="null" top-level-classloader="true">
          
      <requirements>
             <package name="api.offered.by.app.using.infinispan"/>

             <package name="org.apache.log4j"/>
      </requirements> 
      <capabilities>
             <package name="app.service.impl"/>

             <!-- could perhaps even expose the API of Infinispan, for other apps to us? But TBD -->
      </capabilities>
        
      </classloading>

       

      Thanks for your help.

       

      Gilles.

        • 1. Re: Classloaders: How to hide classes from the DefaultDomain?
          Ales Justin Master

          Until JBossAS itself is fully OSGi-zed, you'll have to create such DefaultDomain-replacement manually/programatically.

          Then all other deployments can referece it.

           

          It should be trivial to create such domain, as the api is very simple.

          This might help you:

          * http://java.dzone.com/articles/jboss-microcontainer-classloading

           

          This can be a simple service dropped into deployers/ dir - so it's deployed before any real deployment in deploy/.

          1 of 1 people found this helpful
          • 2. Re: Classloaders: How to hide classes from the DefaultDomain?
            Gilles Compienne Newbie

            Ok, I have applied what is described in the JavaLobby document. So I have created a separate JAR with a single bean, which I use to create the domain "JavaDomain".

             

            public JavaDomainCreator() {

                 log.info("Starting JavaDomainCreator.");

                 clSystem = ClassLoaderSystem.getInstance();

                 log.info("CLS = " + clSystem);

                 clDomain = clSystem.createAndRegisterDomain("JavaDomain"); 
            }

             

            Then, I have changed the classloader deployment descriptor for my application jar in order to make it use the "JavaDomain" as a parent:

             

            <classloading domain="InfinispanCacheDomain" xmlns="urn:jboss:classloading:1.0"
                          import-all="false" parent-first="false" parent-domain="JavaDomain" top-level-classloader="true">
                
            <requirements>
              <package name="test.api"/>
            </requirements> 
            <capabilities>
              <package name="test.service.infinispan_impl"/>
            </capabilities>
              
            </classloading>

            Now, I can see that my classloader has no visibility of the things that are inside the "/jboss-5.1.0.GA/server/zzz" folder. It still has visibility of the "/jboss-5.1.0.GA/lib", but I suspect this is because these are made part of the bootstrap classpath (which is fine with me, but still something to keep in mind).

             

            Now I need to check how I can get this to work in a single JAR file (issue that I need to create the Domain before the "jboss-classloader.xml" probably becomes active), but hopefully I will not have too many issues.

             

            Thanks for your help.

             

            Regards,

             

            Gilles.