cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco class loader can't load classes shared in tomcat

keweishang
Champ in-the-making
Champ in-the-making
Hello,

I have a customized alfresco.war deployed in tomcat and I declared some command processor classes that I created. Instead of putting this classes in the alfresco.war, I want to put them in a tomcat repository and let the tomcat "shared class loader" load these classes.

So I configured the catalina.properties in tomcat by adding this line
shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar
, and I added the myCommandProcessors.jar in the ${catalina.base}/shared/lib/ repository. There are other jar files in this shared repository as well, like the Oracle jdbc driver, which are loaded well by the tomcat shared class loader. But myCommandProcessors.jar cannot be loaded, why? However, when I put the myCommandProcessors.jar in the ${catalina.base}/webapps/alfresco/WEB-INF/lib/, the myCommandProcessors.jar will be loading good, but that's not where I  want to put the the custom jar files to…

I traced the alfresco class load and I found this:
Classloader of command proccessor class:WebappClassLoader
  context: /alfresco
  delegate: false
  repositories:
    /WEB-INF/classes/
———-> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@11568fb5

This is the urls of the classloader:
[file:/home/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/, file:/home/alfresco/tomcat/webapps/alfresco/WEB-INF/lib/FastInfoset-1.2.2.jar, …



Parent Classloader of command proccessor class:org.apache.catalina.loader.StandardClassLoader@11568fb5

This is the urls of the parent classloader:
[file:/home/alfresco/tomcat/shared/classes/, file:/home/alfresco/tomcat/shared/lib/ojdbc6.jar]

Does the line
delegate: false
mean that this class loader does not search classes from it's parent class loader (which is the tomcat shared class loader)?

Thanks.
1 REPLY 1

keweishang
Champ in-the-making
Champ in-the-making
I understand the problem now. The custom classes that I put in the shared repository of tomcat reference the classes in the alfresco.war. While a child class loader can delegate his parent class loader to load class, a parent class loader cannot delegate class loading to his child class loader. That is to say, when tomcat shared loader is loading my custom classes, it cannot get the alfresco classes referenced by my custom classes loaded. So the tomcat shared loader cannot load my custom classes at all. That is the explanation.

A workaround is to produce a amp file which contains the customized classes. Then integrated the alfresco.war + amp file by using an alfresco tool to produce a new alfresco.war who contains the customization.

This post has helped me to find the explanation:
https://forums.alfresco.com/en/viewtopic.php?f=10&t=39109