Class could not be found by the process classloader
fidalma Mar 28, 2006 9:12 AMHi all,
I'm doing several tests with JBpm and in this moment I'm trying
to execute a script command by an ActionHandler class implementation,
but I have a problem and in order to explain it correctly I attach my code.
-------------------------------------- PROCESS DEFINITION -------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="Initiator"> <swimlane name="initiator" /> <start-state name="start new process"> <task swimlane="process initiator" /> <transition name="tr1" to="decision"> <action name="action" class="com.sample.action.SampleActionHendler"> <message>Executing SampleActionHendler!</message> </action> </transition> </start-state> <decision name="decision"> <handler class="com.sample.decision.SampleDecisionHendler"> </handler> <transition name="tr2" to="action"></transition> <transition name="tr3" to="end1"></transition> </decision> <state name="action"> <transition name="tr4" to="end1"></transition> </state> <end-state name="end1"></end-state> </process-definition> ---------------------------------------- MY ACTION HANDLER -------------------------------------- package com.sample.action; import org.jbpm.graph.def.ActionHandler; import org.jbpm.graph.exe.ExecutionContext; public class SampleActionHandler implements ActionHandler { private static final long serialVersionUID = 1L; public void execute(ExecutionContext context) throws Exception { Runtime rt = null; Process process = null; context.getContextInstance().createVariable("greeting", "Greeting from SampleActionHandler"); try { rt = Runtime.getRuntime(); process = rt.exec("C:\\Applications~1\\ECLIPSE~1\\Start.bat"); context.getContextInstance().createVariable("status", new Integer(process.waitFor())); } catch (Exception e) { System.out.println(e); context.getContextInstance().createVariable("budget", new Integer(1)); } } } ------------------------------------- MY DECISION HANDLER -------------------------------------- package com.sample.decision; import org.jbpm.graph.exe.ExecutionContext; import org.jbpm.graph.node.DecisionHandler; public class SampleDecisionHandler implements DecisionHandler { private static final long serialVersionUID = 1L; public String decide(ExecutionContext context) throws Exception { int budget = ((Number)context.getContextInstance().getVariable("status")).intValue(); if (budget == 0) return "tr2"; else if (budget == 1) return "tr3"; else return "tr3"; } } ---------------------------------------- MY TEST CASE ---------------------------------------- package com.sample.test; import com.sample.action.SampleActionHandler; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import junit.framework.TestCase; public class InitiatorTest extends TestCase { public void testProcess() throws Exception { ProcessDefinition definition = ProcessDefinition.parseXmlResource("Initiator.par/processdefinition.xml"); assertNotNull("Definition should not be null", definition); ProcessInstance instance = new ProcessInstance(definition); assertEquals("Instance is in start state", instance.getRootToken().getNode().getName(),"start new process"); instance.signal(); if(((Number)instance.getContextInstance().getVariable("status")).intValue() == 0) { assertEquals(definition.getNode("action"), instance.getRootToken().getNode()); instance.signal(); } assertEquals("Instance is in end state", instance.getRootToken().getNode().getName(),"end1"); } } ---------------------------------- MY EXCEPTION EXECUTING MY TEST CASE ---------------------------------- If I run as JUnit Test my Test Case clss I have theese exceptions: 15:39:09,863 [main] INFO JbpmConfiguration : using jbpm configuration resource 'jbpm.cfg.xml' 15:39:10,269 [main] DEBUG JbpmConfiguration : creating jbpm configuration from input stream 15:39:10,644 [main] DEBUG JpdlParser$JpdlEntityResolver : resolving schema reference publicId(null) systemId(http://jbpm.org/jpdl-3.1.xsd) 15:39:10,644 [main] DEBUG JpdlParser$JpdlEntityResolver : providing input source to local 'jpdl-3.1.xsd' resource 15:39:10,801 [main] WARN JpdlXmlReader : process xml warning: swimlane 'initiator' does not have an assignment 15:39:10,847 [main] DEBUG NodeTypes : node 'page' will not be available. class 'org.jboss.seam.jbpm.Page' couldn't be loaded 15:39:10,910 [main] WARN JpdlXmlReader : process xml warning: task references unknown swimlane 'process initiator':<task xmlns="urn:jbpm.org:jpdl-3.1" swimlane="process initiator" blocking="false" signalling="true" priority="normal"/> 15:39:10,941 [main] WARN JpdlXmlReader : process xml warning: swimlane 'initiator' does not have an assignment 15:39:10,972 [main] DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(Initiator)' for 'Token(/)' 15:39:10,972 [main] DEBUG GraphElement : event 'before-signal' on 'StartState(start new process)' for 'Token(/)' 15:39:10,972 [main] DEBUG GraphElement : event 'node-leave' on 'StartState(start new process)' for 'Token(/)' 15:39:10,972 [main] DEBUG GraphElement : event 'transition' on 'Transition(tr1)' for 'Token(/)' 15:39:10,972 [main] DEBUG GraphElement : executing action 'action[action]' 15:39:10,988 [main] ERROR Delegation : couldn't load delegation class 'com.sample.action.SampleActionHendler' java.lang.ClassNotFoundException: class 'com.sample.action.SampleActionHendler' could not be found by the process classloader at org.jbpm.instantiation.ProcessClassLoader.findClass(ProcessClassLoader.java:60) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at org.jbpm.instantiation.Delegation.instantiate(Delegation.java:140) at org.jbpm.instantiation.Delegation.getInstance(Delegation.java:125) at org.jbpm.graph.def.Action.execute(Action.java:122) at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:235) at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:212) at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:182) at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:166) at org.jbpm.graph.def.Transition.take(Transition.java:106) at org.jbpm.graph.def.Node.leave(Node.java:382) at org.jbpm.graph.node.StartState.leave(StartState.java:70) at org.jbpm.graph.exe.Token.signal(Token.java:174) at org.jbpm.graph.exe.Token.signal(Token.java:123) at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:217) at com.sample.test.InitiatorTest.testProcess(InitiatorTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) 15:39:10,988 [main] ERROR Delegation : couldn't instantiate delegation class 'com.sample.action.SampleActionHendler' java.lang.NullPointerException at org.jbpm.instantiation.FieldInstantiator.newInstance(FieldInstantiator.java:89) at org.jbpm.instantiation.FieldInstantiator.instantiate(FieldInstantiator.java:48) at org.jbpm.instantiation.Delegation.instantiate(Delegation.java:163) at org.jbpm.instantiation.Delegation.getInstance(Delegation.java:125) at org.jbpm.graph.def.Action.execute(Action.java:122) at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:235) at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:212) at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:182) at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:166) at org.jbpm.graph.def.Transition.take(Transition.java:106) at org.jbpm.graph.def.Node.leave(Node.java:382) at org.jbpm.graph.node.StartState.leave(StartState.java:70) at org.jbpm.graph.exe.Token.signal(Token.java:174) at org.jbpm.graph.exe.Token.signal(Token.java:123) at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:217) at com.sample.test.InitiatorTest.testProcess(InitiatorTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) 15:39:11,004 [main] ERROR GraphElement : action threw exception: null java.lang.NullPointerException at org.jbpm.graph.def.Action.execute(Action.java:123) at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:235) at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:212) at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:182) at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:166) at org.jbpm.graph.def.Transition.take(Transition.java:106) at org.jbpm.graph.def.Node.leave(Node.java:382) at org.jbpm.graph.node.StartState.leave(StartState.java:70) at org.jbpm.graph.exe.Token.signal(Token.java:174) at org.jbpm.graph.exe.Token.signal(Token.java:123) at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:217) at com.sample.test.InitiatorTest.testProcess(InitiatorTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) -------------------------------------------------------------------------------------------------
I don't understand why I'm having this error...
Could someone help me please?!
Thank you very much in advance.
Fidalma
Italy