Generating pojos from Flowable XSDs using JAXB

I’d like to use jaxb2 to create my own BPMN xml and I’m having a small issue:
There are a number of XSDs referenced by the BPMN diagrams:


I’m able to generate the POJOs, except when I add in flowable-bpmn-extensions.xsd or activiti-bpmn-extensions-5.4.xsd (depending on which library I pull these out of there seem to be no difference)

When I add the extensions xsd to my list of XSDs to be picked up by jaxb2-maven (xjc)
I get the following exception when generating the pojos:

[ERROR] file:/C:/path/to/project/src/main/resources/flowable_xsd/activiti-bpmn-extensions-5.4.xsd [221,60] 
com.sun.istack.SAXParseException2: Property "Expression" is already defined. Use <jaxb:property> to resolve this conflict.

and a little further down, it says:

[ERROR] file:/C:/path/to/project/src/main/resources/flowable_xsd/activiti-bpmn-extensions-5.4.xsd [225,76] 
com.sun.istack.SAXParseException2: The following location is relevant to the above error

Has anyone done this before/any advice on resolving the issue?

No, haven’t used the extensions with JAXB. However, if you want to generate xml from POJO’s (or vice versa) you can use the BpmnModel. See for example

Does this imply that I would have to build the entire flowable engine project in order to acess the features of this BPMNModel class?

No, the BpmnModel classes are part of the transitive dependencies of the flowable-engine module. So for example when using Maven, adding flowable-engine will automatically add these classes to your classpath.

Thanks, this helped a lot, after asking the question I looked into it a little bit more, for my purposes I’ll need to write the model back to XML after I’ve finished creating it.

This is when I found this method here:

Which references

With that, I simply added a dependency for the BPMN Converter, which pulls BPMN model in as a compile dependency…

Now I have a test that looks like the following, where method createTwoTasksTestProcess() comes from the link you provided initially:

BpmnModel bpmnModel = createTwoTasksTestProcess();
byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
String stringXml = new String(xml);

I think I can work with this much easier from here unless you have any additional feedback or suggestions?