Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating Java Models from XML Schema fails with Spring Boot 3 #236

Open
tinah-1973 opened this issue Dec 16, 2022 · 3 comments
Open

Generating Java Models from XML Schema fails with Spring Boot 3 #236

tinah-1973 opened this issue Dec 16, 2022 · 3 comments

Comments

@tinah-1973
Copy link

tinah-1973 commented Dec 16, 2022

I am currently trying to migrate an application from spring boot 2.7 to Spring Boot 3,
whereby the Spring 6 is using Jakarta EE 9 instead of JEE.
Now I have a problem with the generation of the java models from the xsd file.

This is my plugin configuration:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>3.10</version>
                <dependencies>
                    <dependency>
                        <groupId>org.glassfish.jaxb</groupId>
                        <artifactId>jaxb-runtime</artifactId>
                        <version>4.0.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.andromda.thirdparty.jaxb2_commons</groupId>
                        <artifactId>collection-setter-injector</artifactId>
                        <version>1.0</version>
                    </dependency>
                </dependencies>

                <executions>
                    
                    <execution>
                        <id>xjc-festo-calc-xsd</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>

                            <!-- Package to store the generated file -->
                            <packageName>com.my.company.calculation.jaxb.dto</packageName>
                            <!-- The XSD file that you saved earlier -->
                            <sources>
                                <source>${project.basedir}/src/main/resources/jaxb2/test.xsd</source>
                            </sources>
                            <arguments>-Xcollection-setter-injector</arguments>
                            <extension>true</extension>
                            <clearOutputDir>false</clearOutputDir>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </execution>
                </executions>
</plugin>

Running that plugin leads to follwong debug output :

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:38 min
[INFO] Finished at: 2022-12-16T10:57:06+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:3.1.0:xjc (xjc-festo-calc-xsd) on project electric-sizing-backend: Execution xjc-festo-calc-xsd of goal org.codehaus.mojo:jaxb2-maven-plugin:3.1.0:xjc failed: An AP
I incompatibility was encountered while executing org.codehaus.mojo:jaxb2-maven-plugin:3.1.0:xjc: java.lang.NoSuchMethodError: 'com.sun.xml.bind.api.impl.NameConverter com.sun.tools.xjc.model.Model.getNameConverter()'
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:jaxb2-maven-plugin:3.1.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Develop/_m2repo/org/codehaus/mojo/jaxb2-maven-plugin/3.1.0/jaxb2-maven-plugin-3.1.0.jar
[ERROR] urls[1] = file:/C:/Develop/_m2repo/org/glassfish/jaxb/jaxb-runtime/4.0.1/jaxb-runtime-4.0.1.jar
[ERROR] urls[2] = file:/C:/Develop/_m2repo/org/glassfish/jaxb/jaxb-core/4.0.1/jaxb-core-4.0.1.jar
[ERROR] urls[3] = file:/C:/Develop/_m2repo/jakarta/xml/bind/jakarta.xml.bind-api/4.0.0/jakarta.xml.bind-api-4.0.0.jar
[ERROR] urls[4] = file:/C:/Develop/_m2repo/jakarta/activation/jakarta.activation-api/2.1.0/jakarta.activation-api-2.1.0.jar
[ERROR] urls[5] = file:/C:/Develop/_m2repo/org/eclipse/angus/angus-activation/1.0.0/angus-activation-1.0.0.jar
[ERROR] urls[6] = file:/C:/Develop/_m2repo/org/glassfish/jaxb/txw2/4.0.1/txw2-4.0.1.jar
[ERROR] urls[7] = file:/C:/Develop/_m2repo/org/andromda/thirdparty/jaxb2_commons/collection-setter-injector/1.0/collection-setter-injector-1.0.jar
[ERROR] urls[8] = file:/C:/Develop/_m2repo/com/sun/xml/bind/jaxb-impl/2.1.10/jaxb-impl-2.1.10.jar
[ERROR] urls[9] = file:/C:/Develop/_m2repo/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1.jar
[ERROR] urls[10] = file:/C:/Develop/_m2repo/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar
[ERROR] urls[11] = file:/C:/Develop/_m2repo/javax/activation/activation/1.1/activation-1.1.jar
[ERROR] urls[12] = file:/C:/Develop/_m2repo/com/sun/xml/bind/jaxb-xjc/3.0.0/jaxb-xjc-3.0.0.jar
[ERROR] urls[13] = file:/C:/Develop/_m2repo/com/sun/xml/bind/jaxb-core/3.0.0/jaxb-core-3.0.0.jar
[ERROR] urls[14] = file:/C:/Develop/_m2repo/com/sun/activation/jakarta.activation/2.0.0/jakarta.activation-2.0.0.jar
[ERROR] urls[15] = file:/C:/Develop/_m2repo/com/sun/xml/bind/jaxb-jxc/3.0.0/jaxb-jxc-3.0.0.jar
[ERROR] urls[16] = file:/C:/Develop/_m2repo/com/thoughtworks/qdox/qdox/2.0.1/qdox-2.0.1.jar
[ERROR] urls[17] = file:/C:/Develop/_m2repo/org/codehaus/plexus/plexus-compiler-api/2.11.1/plexus-compiler-api-2.11.1.jar
[ERROR] urls[19] = file:/C:/Develop/_m2repo/org/sonatype/plexus/plexus-build-api/0.0.7/plexus-build-api-0.0.7.jar
[ERROR] urls[20] = file:/C:/Develop/_m2repo/com/sun/istack/istack-commons-runtime/4.0.0/istack-commons-runtime-4.0.0.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]

Why is it still trying to pull in javax packages?
Version 3.1.0 is switched to jakarta, isn't it?
Can someone please help me with this problem?

@tinah-1973
Copy link
Author

tinah-1973 commented Dec 16, 2022

I think I found what the problem is.
I use collection-setter-injector to generate setter for collection fields.
This artifact includes the outdated dependencies.

How can I create setters in Plugin version 3.1.0? Any idea?

@MarkvanOsch
Copy link

A similar issue here, but looks caused by the fluent-api dependency. Has anyone an example of a working configuration setup using the latest 3.1.0 version of the jaxb2-maven-plugin?

@tinah-1973
Copy link
Author

I solved the problem by using at first the getter method to get the List and then use the addAll method to add a List of items. According to the generated Code comment is this the suggested approach.
So no setter is necessary anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants