I have below configuration in my POM file. Especially jaxb-fluent-api configuration.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-Xfluent-api</arg>
</args>
<schemaDirectory>src/main/resources</schemaDirectory>
<plugins>
<plugin>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>2.1.8</version>
</plugin>
</plugins>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Without configuring jaxb-fluent-api entities can be generated from xsd. here what are the benifits using jaxb-fluent-api?
Thanks!
The jaxb-fluent-api
is an JAXB extension, allowing you to generate your code in a fluent api style. Now, fluent api is a way of designing your class methods, so they always return this
instead of void
.
There is a good example on the project wiki (I've shortened it a bit for brevity, visit the site for full example):
Normal JAXB
-generated code must be used like this:
Project project = factory.createProject();
project.setModelVersion("4.0.0");
project.setGroupId("redmosquito")
project.setArtifactId("jaxb-fluent-api-ext")
project.setPackaging("jar")
project.setVersion("0.0.1")
project.setName("JAXB Fluent API Extensions");
With jaxb-fluent-api
extension, you can code the above like this:
Project project = factory.createProject()
.withModelVersion("4.0.0");
.withGroupId("redmosquito")
.withArtifactId("jaxb-fluent-api-ext")
.withPackaging("jar")
.withVersion("0.0.1")
.withName("JAXB Fluent API Extensions");
That's basically what the fluent api is all about.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With