Is there a JAXB Plugin which generates Builders?

爱⌒轻易说出口 提交于 2019-11-30 18:19:54

Yes, there is now a plugin to generate fluent builders for JAXB-generated classes. There is a github project on

https://github.com/mklemm/jaxb2-rich-contract-plugin

It contains a couple of useful JAXB plugins. You can download source and binaries from github, or get maven artifacts from The Central Repository

Hope this helps. If you have any questions, just ask me, I'm the one who started it.

The following snippet from a pom.xml file, uses maven cxf-xjc-plugin to generate the JAXB classes and also leverages jaxb-fluent-api to tack-on fluent interfaces ... which aren't exactly a complete builder pattern on their own ... but I think they leave room for folks to make decent headway in that direction.

        <!-- Used to generate source code based on XSD (schema) file -->
        <!-- http://cxf.apache.org/cxf-xjc-plugin.html -->
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-xjc-plugin</artifactId>
            <version>2.7.7</version>
            <configuration>
                <extensions>
                    <extension>net.java.dev.jaxb2-commons:jaxb-fluent-api:2.1.8</extension>
                </extensions>
            </configuration>
            <executions>
                <execution>
                    <id>generate-xsd-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xsdtojava</goal>
                    </goals>
                    <configuration>
                        <sourceRoot>${basedir}/target/generated-sources/cxf-xjc/</sourceRoot>
                        <xsdOptions>
                            <xsdOption>
                                <xsd>${basedir}/src/main/wsdl/your.xsd</xsd>
                                <packagename>com.your.package.name</packagename>
                                <extensionArgs>
                                    <extensionArg>-Xfluent-api</extensionArg>
                                </extensionArgs>
                            </xsdOption>
                        </xsdOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!