简体   繁体   中英

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

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

I think you have an error in kieSession.startProcess("com.sample.bpmn.hello"); The kieSession didn't know the id: "com.sample.bpmn.hello" , so it throw an error: Unknown Process ID.

Open your bpmn file in text or xml editor and look for this line of code:

    ...
    <process processType="Private" isExecutable="true"  name="Sample Process">
    ...

The is the Process ID. 是进程ID。 So your code should be like this: kieSession.startProcess("Sample");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM