Search code examples
javadroolsrulesjbpmkie

Execute bpmn file from Drools Rule


I would like to execute bpmn file which is in another project. Could anyone tell me how to do this?

I have something like this in my rule, but it's doesn't work:

function performScenario()
{
    KieHelper kHelper = new KieHelper();
    KieBase kBase = kHelper.addResource(ResourceFactory.newFileResource("D:\\jbpm-installer\\workspace\\JbpmTest\\src\\main\\resources\\sample.bpmn")).build();
    KieSession kieSession = kBase.newKieSession();
    kieSession.startProcess("com.sample.bpmn.hello");
}

I have error: Unknown process ID


Solution

  • What do you mean by the process is in another project? You will need to load the project into the same ksession in order to be able to start it from there. Instead of doing this:

    kHelper
        .addResource(
            ResourceFactory.newFileResource("D:\\jbpm-installer\\workspace\\JbpmTest\\src\\main\\resources\\sample.bpmn")
        )
        .build();
    

    Just do the same when you build your rules session and then you will be able to do something like

    kcontext.startProcess(<ID HERE>);
    

    HTH