Call jar from alfresco workflow

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

Call jar from alfresco workflow

I have a jar file with this structure:
ActivitiProj

-src

      --com.mycompany.activiti

         ---Decision.java

-META-INF

      --Manifest.mf

-lib

       --activiti-engine-5.22.0.jar

-alfresco

      --extension

         ---custom-action-context.xml

Decision.java

package com.mycompany.activiti;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

public class Decision implements JavaDelegate
{     
     @Override
     public void execute(DelegateExecution execution) throws Exception
     {
          System.out.println("success test");
     }
}‍‍‍‍‍‍‍‍‍‍‍‍

custom-action-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
   <bean id="custom-action" parent="JavaDelegate" class="com.mycompany.activiti.Decision"/>
</beans>

I stop alfresco, add this jar to alfresco-community\tomcat\webapps\alfresco\WEB-INF\lib

Then in my workflow I add 

<serviceTask id="alfrescoStartScripttask" activiti:class="com.mycompany.activiti.Decision"/>

I start alfresco without any errors in log, deploy my workflow successfull, but when I try to start workflow I have this error in log:

Caused by: java.lang.ClassNotFoundException: com.mycompany.activiti.Decision
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Unknown Source)
     at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:291)
     at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:68)
     ... 153 more

Can anybody help me with this problem? Or maybe there are another ways to call external jars from workflow?
Thank you

4 Replies
Highlighted
Master

Re: Call jar from alfresco workflow

Are you serious about the JAR having the structure you outlined? A JAR addon to Alfresco should never contain other JARs in a lib/ sub folder, and any Java code needs to be included as compiled *.class files in a JAR (unless it is a JavaDoc or source JAR). How are you creating the JAR? It is highly recommended to use the Alfresco SDK if you are new to Alfresco development. You may also want to check out Jeff Potts' tutorial about advanced workflows in Alfresco.

Highlighted
Active Member II

Re: Call jar from alfresco workflow

Axel, I am sorry, can you please explain what do you mean? why I can't add one jar to another?
I can call my jar with the same structure  from alfresco workflow, I just need to add .xml file here: 
alfresco-community\tomcat\shared\classes\alfresco\extension

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

    <bean id="decision" class="validationdecision.ValidationDecision">
    </bean>

</beans>‍‍‍‍‍‍‍‍

and put my jar here
alfresco-community\tomcat\webapps\alfresco\WEB-INF\lib

and add to my workflow

<serviceTask id="alfrescoScriptTask" activiti:class="validationdecision.ValidationDecision"/>

So my class ValidationDecision looks like: (just for testing)

public class ValidationDecision implements JavaDelegate
{
     @Override
     public void execute(DelegateExecution execution) throws Exception
     {
                System.out.println (execution.getVariable("docId").toString());
     }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And I can see valid docId output in log here alfresco-community\tomcat\logs\alfrescotomcat-1-stdout (when I start my workflow ofcourse).

So jar is called successfully.

Highlighted
Master

Re: Call jar from alfresco workflow

What I pointed out was that the JAR structure you outlined in your original question would not work.

a) It contains source code, not a compiiled class, and

b) it contains the activiti-engine JAR, which is both unnecessary (Alfresco already incldues Activiti) and without effect (JARs inside JARs should not be loaded by the default class loaders)

What you may have failed to mention is that this may not have been the final JAR structure but your source project structure, with the final JAR file looking completely different.

Apparently the JAR in your own reply contains a different class and maybe a different structure to the original issue.

Highlighted
Active Member II

Re: Call jar from alfresco workflow

Oh, of course u r right, this is just a project structure, it's my fault)