Home > Blockchain >  cxf-xjc-plugin: generate javax instead of jakarta imports
cxf-xjc-plugin: generate javax instead of jakarta imports

Time:09-02

How to configure latest org.apache.cxf plugin to generate java classes with javax instead of jakarta imports?

            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <version>4.0.0</version>
                <configuration>
                    <extensions>
                        <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:4.0.0</extension>
                    </extensions>
                </configuration>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                        <configuration>
                            <sourceRoot>${basedir}/src/gen/java</sourceRoot>
                            <xsdOptions>
                                <xsdOption>
                                    <xsd>${basedir}/src/main/resources/xslt/MySchema.xsd</xsd>
                                    <packagename>some.package</packagename>
                                </xsdOption>
                            </xsdOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Downgrading plugin to version 2.7.0 helps but it has problems with generating javaDocs, e.g. > signs are not escaped properly.

CodePudding user response:

Ok so using org.apache.cxf:cxf-xjc-plugin:3.3.2 solves my problem. It escapes properly javaDoc and generates classes with javax.xml.bind... imports.

            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <version>3.3.2</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                        <configuration>
                            <sourceRoot>${basedir}/src/gen/java</sourceRoot>
                            <xsdOptions>
                                <xsdOption>
                                    <xsd>${basedir}/src/main/resources/xslt/MySchema.xsd</xsd>
                                    <packagename>some.package</packagename>
                                </xsdOption>
                            </xsdOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

After analysing dependencies it looks like the plugin uses jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 which has javax.xml.bind as main package (which changes to jakarta.xml.bind starting with version 3.0.1).

  • Related