Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate pojos from multiple xsd with cxf-xjc-plugin?

Tags:

java

maven

xjc

cxf

I'd like to use the maven cxf-xjc-plugin plugin to java classes from xsd files. I have approx 30 xsd files, which I'd have to link explicit each of them inside xsdOptions.

Is it possible to provide wilcard matching for this plugin to generate from any xsd files found?

like image 242
membersound Avatar asked Jan 25 '16 14:01

membersound


1 Answers

Unfortunately, this plugin forces the developer to write the path for each XSD. You can't use a wildcard for specifying the path to XSD files.

However, there has been an undocumented update made to the plugin that allows to specify a directory instead of a list of files. As such, if all of your XSDs are inside the same directory, you can specify this. I tracked the changed to this email from the cxf-commits mailing list, dated July 2015, from [email protected]:

Convenience option for configuring the code generation from XSD files: Instead of having to explicitly list every single file using the <xsd> element, now the new <xsdDir> element can be used instead for specifying a directory. From this directory all *.xsd files will be used for code generation.

This attribute is not documented but you can find it in the source code for version 3.0.5 for example.

You could then have the following configuration:

<xsdOption>
  <xsdDir>/path/to/directory/having/all/XSD</xsdDir>
  <!-- rest of configuration -->
</xsdOption>

Do note that, from reading the source code, the search for XSD files is not recursive: all XSD must be placed inside this directory and not into subdirectories for the plugin to find them.

like image 74
Tunaki Avatar answered Sep 20 '22 08:09

Tunaki