AnsweredAssumed Answered

Load class file from shared/lib with alfresco dependency

Question asked by loftux Moderator on Jun 2, 2011
Latest reply on Mar 24, 2015 by gravitonian
Is there a way for a custom class to be placed in shared/lib and still load dependencies in WEB-INF/lib?

Background
I was trying to move away from amp file distribution to all jar for alfresco addons. This works well for all non java stuff, but for my jar with a custom java class extending/dependent on alfresco classes it only loads when placed in WEB-INF/lib. I would like to place it in shared/lib, in that way it will be kept between alfresco.war redeploys.

What I have tested
I have a bean loading from
shared/classes/alfresco/module/loftux/context/service-context.xml
<bean id="loftuxutilsScript" parent="baseJavaScriptExtension" class="se.loftux.repo.jscript.LoftuxScriptUtils">
        <property name="extensionName">
            <value>loftuxutils</value>
        </property>
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>
My jar is loftux.alfresco.jar.
The class is a simple extension in java to add utility functions to javascript. It therefor is dependent on bean baseJavaScriptExtension. That bean is found in one of the jars in WEB-INF/lib.

If I place my jar in WEB-INF/lib it loads just fine. If placed in any other lib directory it fails with (only part of the error pasted)
09:35:49,373 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LuceneFullTextSearchIndexer' defined in class path resource [alfresco/core-services-context.xml]: Cannot resolve reference to bean 'luceneFullTextSearchIndexer' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'luceneFullTextSearchIndexer' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.loftux.repo.jscript.LoftuxScriptUtils] for bean with name 'loftuxutilsScript' defined in URL [file:/opt/alfresco/loftux/tomcat/shared/classes/alfresco/module/loftux/context/service-context.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/alfresco/repo/jscript/BaseScopableProcessorExtension
i.e it cannot find a class file needed.
So from what I can tell from reading http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html classes in WEB-INF/lib can read from lib folders higher in the hiearchy, but the other way around (the way I want to) isn't possible.

Or is there a way with som spring bean config magic, or tomcat class loading config?

Outcomes