1

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.

makozaki
  • 3,772
  • 4
  • 23
  • 47
  • 1
    I think javax or jakarta are bound to the plugin version if it doesn’t specify a configuration option to change this. – slindenau Aug 29 '22 at 14:42
  • I'm thinking maybe some dependency management could do the trick. It's working by mistake like that in one of my projects but can't figure out why, I suspect due to project dependencies. – makozaki Aug 29 '22 at 18:47

1 Answers1

1

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).

makozaki
  • 3,772
  • 4
  • 23
  • 47