How to overlay class from jar

cancel
Showing results for 
Search instead for 
Did you mean: 
xyz
Active Member

How to overlay class from jar

Jump to solution

I have a class which is tweaked in some particular way and this is class from alfresco-repository7.43.jar. I want to overlay this class. Inside my repo container I have my customized class in ./webapps/alfresco/WEB-INF/classes/... and  basic class inside ./webapps/alfresco/WEB-INF/lib/alfresco-repository-7.43.jar. Unfortunately alfresco uses class from alfresco-repository-7.43.jar not from /classes/... . Path leading to this class is the same in both cases, so it's not the case. I want to force alfresco somehow to use class from /classes/.. not from .jar. I'm using all-in-one, alfresco 6,1.

Any help would be greately appreciated.Smiley Happy

1 Solution

Accepted Solutions
afaust
Master

Re: How to overlay class from jar

Jump to solution

Even if you think you need to change one of Alfresco's distributed classes, there are typically better options to forking and rebuilding. Subclassing or facading is generally preferable as it allows you to focus your custom code on the specific change you want to effect, and makes upgrading Alfresco easier in the long run, because you don't have to look through an entire fork for any changes you may need to adapt to a new version. Using Spring XML and bean post processors, it is also quite easy to replace / augment Alfresco default services with your sub-classed / facaded fixes (an example would be my replacement of the default virtual store implementation with a subclass)

View solution in original post

4 Replies
jpotts
Professional

Re: How to overlay class from jar

Jump to solution

Without knowing any additional details or context, this sounds like something you should not be doing.

If you need to change one of Alfresco's distributed class files (highly unlikely) then fork the source, make your change and do a build. Then, run with that build.

If you are trying to extend an Alfresco class, extend it through normal Java mechanisms, then, if you need to, override the Spring bean in your own custom Spring context file to point to your custom extended class.

If you just change a class and put it on the classpath you are subjecting yourself to the vagaries of the classloader which could be a nightmare if you need to troubleshoot or debug.

afaust
Master

Re: How to overlay class from jar

Jump to solution

Even if you think you need to change one of Alfresco's distributed classes, there are typically better options to forking and rebuilding. Subclassing or facading is generally preferable as it allows you to focus your custom code on the specific change you want to effect, and makes upgrading Alfresco easier in the long run, because you don't have to look through an entire fork for any changes you may need to adapt to a new version. Using Spring XML and bean post processors, it is also quite easy to replace / augment Alfresco default services with your sub-classed / facaded fixes (an example would be my replacement of the default virtual store implementation with a subclass)

xyz
Active Member

Re: How to overlay class from jar

Jump to solution

I appreciate your answer. Yet, I want to add one thing. To be honest is it possible to overlay jar class by simple modifing alfresco class and reregister it in context. I tried it. But this will inevitable lead to problem with debugging code. Intellij, heh If you use one, will not use your class in debug mode but class from jar, which can lead you to wrong conclusion. 

EddieMay
Alfresco Employee

Re: How to overlay class from jar

Jump to solution

Hi @xyz,

Lots of things are possible but not all of them are advisable - this is one of the latter Smiley Happy 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!