[jboss-user] [JBoss Microcontainer] - Custom ClassLoader

Irfan Basha do-not-reply at jboss.com
Tue Mar 26 03:34:37 EDT 2013


Irfan Basha [https://community.jboss.org/people/irbash] created the discussion

"Custom ClassLoader"

To view the discussion, visit: https://community.jboss.org/message/804773#804773

--------------------------------------------------------------
Hi All, 

I am trying to create a custom classloader which I can use to load few classes in my war (may be complete war in future). 

I found this article which explains how a custom classloader can be created: 
(Custom ClassLoader (classloader-beans.xml))  http://java.dzone.com/articles/a-look-inside-jboss-microconta-0 http://java.dzone.com/articles/a-look-inside-jboss-microconta-0

I have few clarifications in this: 
1) Where should I put the content of classloader-beans.xml ? (I have currently put it in jboss-beans.xml and placed it in WEB-INF)
2) Correct me if am wrong: The bean CB2 will be loaded using the customClassLoader... right ?

This is how my jboss-beans.xml looks like: 
+<deployment xmlns="urn:jboss:bean-deployer:2.0">+
+          <classloader>+
+                    <inject bean="custom-classloader:0.0.0" />+
+          </classloader>+

+          <classloader name="custom-classloader" xmlns="urn:jboss:classloader:1.0"+
+                    export-all="NON_EMPTY" import-all="true" />+
+          <bean name="CustomCL" class="com.beans.CustomClassLoader">+
+                    <constructor>+
+                              <parameter>+
+                                        <inject bean="custom-classloader:0.0.0" />+
+                              </parameter>+
+                    </constructor>+

+          </bean>+
+          <bean name="CB1" class="com.Sample">+
+          <classloader>+
+                    <inject bean="CustomCL" />+
+          </classloader>+
+</bean>+
+</deployment>+

And I have the class CustomeClassLoader which just extends ClassLoader: 

public class CustomClassLoader extends ClassLoader
{
   private Pattern pattern;
   public CustomClassLoader(ClassLoader parent)
   {
      super(parent);
   }
   public Class<?> loadClass(String name) throws ClassNotFoundException
   {
      if (pattern == null || pattern.matcher(name).matches())
         return super.loadClass(name);
      else
         throw new ClassNotFoundException("Name '" + name + "' doesn't match pattern: " + pattern);
   }
   public void setPattern(String regexp)
   {
      pattern = Pattern.compile(regexp);
   }
}

and when I start JBoss I get this following error: 
08:28:51,677 ERROR [AbstractKernelController] Error installing to PreInstall: na
me=CustomCL state=Real
java.lang.ClassNotFoundException: com.beans.CustomClassLoader
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:428)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:360)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseCl
assLoaderDomain.java:304)
        at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseCl
assLoaderDomain.java:1172)
        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(Ba
seClassLoader.java:1264)
        at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassL
oader.java:549)
        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoa
der.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:360)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryI
mpl.resolveComplexTypeInfo(IntrospectionTypeInfoFactoryImpl.java:419)
        at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryI
mpl.getTypeInfo(IntrospectionTypeInfoFactoryImpl.java:388)
        at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory.
getTypeInfo(IntrospectionTypeInfoFactory.java:54)
        at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapt
er(BasicClassAdapterFactory.java:61)
        at org.jboss.config.plugins.AbstractConfiguration.getBeanInfo(AbstractCo
nfiguration.java:86)
        at org.jboss.kernel.plugins.config.AbstractKernelConfig.getBeanInfo(Abst
ractKernelConfig.java:80)
        at org.jboss.kernel.plugins.config.AbstractKernelConfigurator.getBeanInf
o(AbstractKernelConfigurator.java:77)
        at org.jboss.kernel.plugins.config.AbstractKernelConfigurator.getBeanInf
o(AbstractKernelConfigurator.java:96)
        at org.jboss.kernel.plugins.dependency.PreInstallAction.installActionInt
ernal(PreInstallAction.java:90)
        at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction
(InstallsAwareAction.java:54)
        at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction
(InstallsAwareAction.java:42)
        at org.jboss.dependency.plugins.action.SimpleControllerContextAction.sim
pleInstallAction(SimpleControllerContextAction.java:62)
        at org.jboss.dependency.plugins.action.AccessControllerContextAction.ins
tall(AccessControllerContextAction.java:71)
        at org.jboss.dependency.plugins.AbstractControllerContextActions.install
(AbstractControllerContextActions.java:51)
        at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
ctControllerContext.java:348)
        at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
oller.java:1631)
        at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
ctController.java:934)
        at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
actController.java:1082)
        at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
actController.java:984)
        at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
oller.java:774)
        at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
oller.java:540)
        at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(B
eanMetaDataDeployer.java:121)
        at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(B
eanMetaDataDeployer.java:51)
        at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.i
nternalDeploy(AbstractSimpleRealDeployer.java:62)
        at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(
AbstractRealDeployer.java:50)
        at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(Deployer
Wrapper.java:171)
        at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(Deployer
sImpl.java:1439)
        at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFi
rst(DeployersImpl.java:1157)
        at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFi
rst(DeployersImpl.java:1178)
        at org.jboss.deployers.plugins.deployers.DeployersImpl.install(Deployers
Impl.java:1098)
        at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
ctControllerContext.java:348)
        at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
oller.java:1631)
        at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
ctController.java:934)
        at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
actController.java:1082)
        at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
actController.java:984)
        at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
ller.java:822)
        at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
ller.java:553)
        at org.jboss.deployers.plugins.deployers.DeployersImpl.process(Deployers
Impl.java:781)
        at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeploye
rImpl.java:702)
        at org.jboss.system.server.profileservice.repository.MainDeployerAdapter
.process(MainDeployerAdapter.java:117)
        at org.jboss.system.server.profileservice.repository.ProfileDeployAction
.install(ProfileDeployAction.java:70)
        at org.jboss.system.server.profileservice.repository.AbstractProfileActi
on.install(AbstractProfileAction.java:53)
        at org.jboss.system.server.profileservice.repository.AbstractProfileServ
ice.install(AbstractProfileService.java:361)
        at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
ctControllerContext.java:348)
        at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
oller.java:1631)
        at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
ctController.java:934)
        at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
actController.java:1082)
        at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
actController.java:984)
        at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
ller.java:822)
        at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
ller.java:553)
        at org.jboss.system.server.profileservice.repository.AbstractProfileServ
ice.activateProfile(AbstractProfileService.java:306)
        at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(
ProfileServiceBootstrap.java:271)
        at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:
461)
        at org.jboss.Main.boot(Main.java:221)
        at org.jboss.Main$1.run(Main.java:556)


DEPLOYMENTS MISSING DEPENDENCIES:
  Deployment "CB1" is missing the following dependencies:
    Dependency "CustomCL" (should be in state "PreInstall", but is actually in s
tate "**ERROR**")


DEPLOYMENTS IN ERROR:
  Deployment "CustomCL" is in error due to the following reason(s): java.lang.Cl
assNotFoundException: com.beans.CustomClassLoader, **ERROR**




Can anyone help in solving this problem. 
>From the above error, it seems that the baseClassLoader doesn't know where com.beans.CustomClassLoader is located. 

Thanks in advance,
Irfan
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/804773#804773]

Start a new discussion in JBoss Microcontainer at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2114]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130326/a153dd68/attachment-0001.html 


More information about the jboss-user mailing list