3 Replies Latest reply on Apr 24, 2015 10:35 AM by frenky1983

    How to call Java class from Script Task in JBPM

    kalesha786

      Hi,

       

      Can someone guide me to achieve below task..

       

        I have placed Java code in script task to execute and to complete the process.. Instead of placing java code in Script task, Is there any way to achieve below..

       

      1.. Place the java code in Java class file..

      2. Call the Java class from script task to execute.. If yes, please share the steps to do this..

        • 1. Re: How to call Java class from Script Task in JBPM
          frenky1983

          You must add the dependency from the artifact that contains the your class (e.g. TestService()) in project authoriting -> artifact repository (or add that dependency as a module in jboss)

          than you can use the class in you script task as in a normal java program.

          you must instantiate only your class and call your method

           

          it.example.TestService service = new it.example.TestService(); \\all the package path is required for me, i don't know if is necessary

          service.executeMethod();

          .......

          • 2. Re: How to call Java class from Script Task in JBPM
            kalesha786

            Thank You.. It worked for me..

             

               One more query..

             

            I started the process from a java class.

                    ProcessInstance processInstance = ksession.startProcess(processName,params);

            After this, it started executing my script task nodes.. Now, i want to send result from script task node to java class where i called startprocess()..

             

              Can you tell me how to do this?

             

            -

            • 3. Re: How to call Java class from Script Task in JBPM
              frenky1983

              Someone will correct me if i wrong,

              i think you can set a process variable in your script task, something like this

               

              kcontext.getKnowledgeRuntime().setVariable("variable", "value");

               

              and then recover that variable in your java class in similary manner

               

              i hope this is helpful for you