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

Getting exception package javax.xml.bind.annotation does not exist with JDK 17 #279

Closed
Gus-2 opened this issue Jul 18, 2023 · 41 comments
Closed
Labels
jaxb4 Issue with jaxb 4.x maven-plugin Issue concerns maven plugin
Milestone

Comments

@Gus-2
Copy link

Gus-2 commented Jul 18, 2023

Hi,

I am having an issue while generating classes based on a wsdl file.

I do get the warning :

org.xml.sax.SAXParseException: Are you trying to compile WSDL? Support for WSDL is experimental. You may enable it by using the -wsdl option.
    at com.sun.tools.xjc.ErrorReceiver.warning (ErrorReceiver.java:76)
    at com.sun.tools.xjc.ModelLoader.sanityCheck (ModelLoader.java:176)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:90)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:76)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.loadModel (XJC23Mojo.java:50)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute (XJC23Mojo.java:40)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute (XJC23Mojo.java:28)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute (RawXJC2Mojo.java:477)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute (RawXJC2Mojo.java:319)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

But as already discussed #243 , the files are correctly generated.

The issue is that I am getting this error when opening the generated files : package javax.xml.bind.annotation does not exist

I am using JDK 17, Springboot version 3.1.1.

Here is the pom file configuration :

<plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.15.3</version>
      <executions>
          <execution>
              <goals>
                  <goal>generate</goal>
              </goals>
          </execution>
      </executions>
      <configuration>
          <schemaLanguage>WSDL</schemaLanguage>
          <generatePackage>apiconsumer.wsdl</generatePackage>
          <schemaDirectory>src/main/resources/api/</schemaDirectory>
          <schemaIncludes>
              <schemaInclude>*.wsdl</schemaInclude>
          </schemaIncludes>
          <catalog>src/main/resources/api/catalog.cat</catalog>
          <strict>false</strict>
          <bindingDirectory>src/main/resources/api/</bindingDirectory>
          <bindingIncludes>binding.xjb</bindingIncludes>
          <extension>true</extension>
          <args>
              <arg>-Xannotate</arg>
              <arg>-XremoveAnnotation</arg>
          </args>
          <plugins>
              <plugin>
                  <groupId>org.jvnet.jaxb2_commons</groupId>
                  <artifactId>jaxb2-basics-annotate</artifactId>
                  <version>1.1.0</version>
              </plugin>
          </plugins>
      </configuration>
  </plugin>
@laurentschoelens
Copy link
Collaborator

Hi @Gus-2

The support of jakarta is currently under progress. We know that a lot of people are waiting for it and hope to provide it soon with both v3 and v4 of this plugin.
We need first to get merged repos (maven-plugin / jaxb-basics) since they depend on each other for building jakarta version.

V3 : will support jakarta with jaxb 3 and jdk8 baseline
V4 : will also support jakarta with jaxb 4 and jdk11 baseline

Regards

@laurentschoelens
Copy link
Collaborator

See also if this tip can provide you a QW for your build
#233 (comment)

@Gus-2
Copy link
Author

Gus-2 commented Jul 19, 2023

Ok Good luck ! #233 did help. Thanks for the quick answer

@laurentschoelens
Copy link
Collaborator

Linked to #199

@icarusfire
Copy link

icarusfire commented Jul 26, 2023

@laurentschoelens Hi Laurent, we are trying to decide if we should wait for the jakarta support which you mentioned under progress, or completely find a different solution. We also have dependencies to a variety of basicjaxb plugins, and we use jaxb4. Not to put any pressure, but do you have a ballpark number when can we expect this? more like in weeks or months? thanks

@laurentschoelens
Copy link
Collaborator

Hi @icarusfire
Thanks for the interest in original maven-jaxb2-plugin (renamed recently in jaxb-maven-plugin)
As pointed in my previous comment, you can use this QW : #233 (comment) to make it build with jakarta support.

We are currently working on 2.X version with 3 repos merged (this one, basics, annotate).
After that, we'll cut off the 3.X branch and provide original support for jaxb3-jakarta version.
And after that, we'll cut off the 4.X branch to provide support for jaxb4-jakarta version and jdk11 baseline.

@icarusfire
Copy link

@laurentschoelens Thanks, is that solution going to help with basicjaxb plugin dependecnies and when using jaxb4?

@laurentschoelens
Copy link
Collaborator

It depends which basicjaxb plugins you're using but I guess that you're using ones that generate annotation with jaxb-javax version. Could you give it a try first and tell me if it works ?

@icarusfire
Copy link

icarusfire commented Jul 26, 2023

I have this error:
'Unable to parse configuration of mojo org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.15.1:generate for parameter executions: Cannot find 'executions' in class org.apache.maven.model.Dependency '

I use maven-jaxb2-plugin which also depends on:

jaxb-xew-plugin
jaxb2-basics
jaxb2-basics-tools
jaxb2-basics-annotate

@laurentschoelens
Copy link
Collaborator

Could you use the 2.0.2 version ?

<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>2.0.2</version>

@icarusfire
Copy link

icarusfire commented Jul 26, 2023

still same error : )
Unable to parse configuration of mojo org.jvnet.jaxb:jaxb-maven-plugin:2.0.2:generate for parameter executions: Cannot find 'executions' in class org.apache.maven.model.Dependency

here more details about my config:

<executions>
  <execution>
    <id>aa</id>
    <phase>generate-sources</phase>
    <goals>
      <goal>generate</goal>
    </goals>
    <configuration>
      <schemaDirectory>target/generated-resources</schemaDirectory>
      <generateDirectory>${project.build.directory}/generated-sources/xjc-aa
      </generateDirectory>
      <schemaIncludes>
        <schemaInclude>aa.xsd</schemaInclude>
        <schemaInclude>bb.xsd</schemaInclude>
      </schemaIncludes>
      <bindingIncludes>
        <bindingInclude>cc.xjb</bindingInclude>
      </bindingIncludes>
      <extension>true</extension>
    </configuration>
  </execution>
</executions>
<configuration>
  <args>
    <arg>-Xinheritance</arg>
    <arg>-Xxew</arg>
    <arg>-Xannotate</arg>
  </args>
  <plugins>
…

@laurentschoelens
Copy link
Collaborator

Could you provide more context ?
It looks like the pom is not ok and as jaxb-maven-plugin is in dependency section and not in plugin section

@icarusfire
Copy link

ant plugin should be outside..my bad trying again

@icarusfire
Copy link

ok now I get Unable to parse input schema(s). Error messages should have been provided.

@laurentschoelens
Copy link
Collaborator

you should have a more detailed error in the upper log of the build

@laurentschoelens
Copy link
Collaborator

Also the jaxb-basics-tools should not be included in my opinion. You only need jaxb-basics dep in plugin section (see https://github.com/highsource/jaxb2-basics/wiki/Using-JAXB2-Basics-Plugins#using-jaxb-plugins-with-maven) and jaxb2-basics-runtime in dependency of project

@icarusfire
Copy link

icarusfire commented Jul 26, 2023

org.xml.sax.SAXParseException: Attribute "xmlns:jxb" was already specified for element "jxb:bindings".
btw this is how my xjb starts:
<jxb:bindings version="3.0" xmlns:jxb="https://jakarta.ee/xml/ns/jaxb" version="2.1"

@icarusfire
Copy link

never mind found the problem, run again now this:
The root element must be {http://java.sun.com/xml/ns/jaxb}bindings but it is {https://jakarta.ee/xml/ns/jaxb}bindings

@laurentschoelens
Copy link
Collaborator

guess you should have a binding in "javax" mode, since you're generating javax classes and ant-maven is going to replace javax by jakarta after generation

@icarusfire
Copy link

i did that and got this:
Execution mdm-generic of goal org.jvnet.jaxb:jaxb-maven-plugin:2.0.2:generate failed: An API incompatibility was encountered while executing org.jvnet.jaxb:jaxb-maven-plugin:2.0.2:generate: java.lang.NoSuchMethodError: 'java.lang.Object org.jvnet.jaxb2_commons.util.CustomizationUtils.unmarshall(javax.xml.bind.JAXBContext, com.sun.tools.xjc.model.CPluginCustomization)'

@laurentschoelens
Copy link
Collaborator

which version of jaxb2-basics are you using ?

@icarusfire
Copy link

icarusfire commented Jul 26, 2023

1.11.1

and these are the plugins again:
jaxb-xew-plugin
jaxb2-basics
jaxb2-basics-tools
jaxb2-basics-annotate

@laurentschoelens
Copy link
Collaborator

1.11.1 should not be used -> release by mistake : try 0.13.1
also remove jaxb2-basics-tools from plugin

@icarusfire
Copy link

icarusfire commented Jul 26, 2023

ok this is my current setup, and still has teh same error:

: An API incompatibility was encountered while executing org.jvnet.jaxb:jaxb-maven-plugin:2.0.2:generate: java.lang.NoSuchMethodError: 'java.lang.Object org.jvnet.jaxb2_commons.util.CustomizationUtils.unmarshall(javax.xml.bind.JAXBContext, com.sun.tools.xjc.model.CPluginCustomization)'


 <plugins>
            <plugin>
              <groupId>com.github.jaxb-xew-plugin</groupId>
              <artifactId>jaxb-xew-plugin</artifactId>
              <version>2.1</version>
            </plugin>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics</artifactId>
              <version>0.13.1</version>
            </plugin>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics-annotate</artifactId>
              <version>1.1.0</version>
            </plugin>
          </plugins>

@laurentschoelens
Copy link
Collaborator

This is a bit weird
Try without xew plugin ans arg
If doesn't work i'll dig why it complains of api incompatibility of jaxb basics
Still we made some progress

@icarusfire
Copy link

wow I think it worked now, I see it created classes(not sure it did correctly but they are there). So what about the xew plugin we removed?

@laurentschoelens
Copy link
Collaborator

I'll look more deeper tomorrow but xew depends on jaxb-basics so I guess it mismatched config.
See if you need it or not

@icarusfire
Copy link

ok thanks and how do i know if i need it, I am middle of migration and nothing works right now, so passing unit tests is a long way to go :)

@icarusfire
Copy link

but regardless thanks a lot for your help! let me know if you find out more tomorrow. good night

@laurentschoelens
Copy link
Collaborator

You're welcome
Look at xew jaxb plugin readme page to see what it does.
It simplifies code generation to avoid some weird code.
I'll let you know if I find something interesting.
Good night too 😄

@laurentschoelens
Copy link
Collaborator

you should use xew 1.11 version (bases on jaxb-basics 0.12.0)
2.x branch should be used with future jakarta version of the plugin
it should work with that change

@icarusfire
Copy link

thank you!

@laurentschoelens
Copy link
Collaborator

thank you!

Tell me if it worked.
If so, you should be able to have generated classes just as before but with jakarta import (so compatible with SB3 and without breaking code)

@icarusfire
Copy link

works! btw what is the difference between the suggested org.jvnet.jaxb plugin and the one I was using

@laurentschoelens
Copy link
Collaborator

Just the same.
We just renamed the maven-jaxb2-plugin in group org.jvnet.jaxb2.maven2 to jaxb-maven-plugin in group org.jvnet.jaxb in 2.x release

@laurentschoelens
Copy link
Collaborator

laurentschoelens commented Jul 26, 2023

Just the same.
We just renamed the maven-jaxb2-plugin in group org.jvnet.jaxb2.maven2 to jaxb-maven-plugin in group org.jvnet.jaxb in 2.x release

See #262 and release note of 2.0.2

@icarusfire
Copy link

you mentioned above "and jaxb2-basics-runtime in dependency of project" is this still necessary?

@laurentschoelens
Copy link
Collaborator

you mentioned above "and jaxb2-basics-runtime in dependency of project" is this still necessary?

No if not already in your legacy dependencies, you can remove it.
Only necessary when using some of the specific plugins of jaxb2-basics

@laurentschoelens laurentschoelens added maven-plugin Issue concerns maven plugin jaxb4 Issue with jaxb 4.x labels Aug 16, 2023
@mattrpav
Copy link
Collaborator

#389 javax -> jakarta support
#341 xew w/ jakarta support alternative implementation (to be added to jaxb-tools)

@laurentschoelens
Copy link
Collaborator

@Gus-2 : v4 based on jaxb-ri 4.0.2 will be out in few hours
@icarusfire : you should be able to also move to new version of the plugin with official jakarta support
Don't forget to look at migration guide

@laurentschoelens
Copy link
Collaborator

Fixed by #410

@laurentschoelens laurentschoelens added this to the 4.0.0 milestone Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jaxb4 Issue with jaxb 4.x maven-plugin Issue concerns maven plugin
Projects
None yet
Development

No branches or pull requests

4 participants