maven jaxb plugin configuration to generate XSD schema files

Here is how to configure your project in order to generate XSD schema files from Java JAXB annotated classes


This will generate an XSD file named ${xsd_filename} in the target/schemas folder.

We chose the generate-source phase in order to make the schema file available for the sources (particularly for the test sources), in conjunction with the following resources configuration to add the schema to the generated artifact:


A Maven configuration for a Java Webstart (JNLP) application – 2

In a previous post I detailed the Maven configuration to generate a Java Webstart application using the webstart-maven-plugin along with the maven-shade-plugin (the shade plugin allows to generate auto-executable jars).

I faced some troubles when I tried to use this configuration in another application requiring access to system resources (accessing files and directories for read and write operations) and using third party trusted libraries:

When the application needs grant access system resources, you must ask for that grant through the all-permissions configuration element in the jnlp file


However, to do this, you must sign all the jars: the application jar and the third party jars the application needs, and generally the third party jars you are using are signed and this makes the maven-shade-plugin fail when processing the whole. Even more, if the whole application is not signed with the same certification authority, it will fail executing on the client side.

So I ended up with this webstart-maven-plugin configuration (which happens to be even simpler than the one on my previous post):


Note also that there is no need to the maven-shade-plugin.

The unsignAlreadySignedJars property allows to unsign the third party libraries you are using, and signing them again with your signing configuration.

Replace in the above plugin configuration the ${jnlp.URL}, ${mainClass} and ${jks.X} parameters with yours.

Customize your XML using Transform

A colleague of mine had a problem when generating an XML file (that he could not solve neither using XMLBeans nor using JAXB): his issue was to add a standalone=”no” in the XML file declaration (to be compliant with a third party specifications). You have to know that when setting standalone attribute to “no”, both libraries simply ignore that attribute (cause it’s the default value) and there is no way to get around that. We (I’d rather say He) have found a solution using the javax.xml.transform.Transformer class. In few words, this class allows you to transform a tree representation onto another tree representation, customizing and overriding any field attribute transformation.

Here is the way we achieved our goal (setting standalone=”on”) that could serve as a base usage example:

// get a new instance
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // to properly indent XML
StreamResult output = new StreamResult(new FileWriter(file2)); // output file to transform
StreamSource source = new StreamSource(file); // input file to transform
transformer.transform(source, output);