highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
108 stars 54 forks source link

Working support for Jakarta version of XJC #129

Closed sebersole closed 7 months ago

sebersole commented 2 years ago

Working support for Jakarta XJC

sebersole commented 2 years ago

I had to skip tests in order to build this. The tests explicitly use some com.sun references and I am not sure how to address those. But I have verified that the resulting artifacts work in my build (through one of my Gradle plugins)

JWT007 commented 1 year ago

Sorry to jump in here as I am not a contributor :/

I am trying to use @sebersole 's fork as a temporary solution to the jakarta problem with the equals/hashcode/toString plugins. It also seems to be working for me - thanks a million for that! :)

I did notice a few things which might be added under "cleanup" :)

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.167 s <<< FAILURE! - in org.jvnet.jaxb2_commons.xjc.model.concrete.tests.alpha.AlphaMInfoFactoryTest
[ERROR] org.jvnet.jaxb2_commons.xjc.model.concrete.tests.alpha.AlphaMInfoFactoryTest  Time elapsed: 0.167 s  <<< ERROR!
java.lang.IllegalArgumentException: can't parse argument number: ''https://jakarta.ee/xml/ns/jaxb''
    at org.jvnet.jaxb2_commons.xjc.model.concrete.tests.alpha.AlphaMInfoFactoryTest.createModel(AlphaMInfoFactoryTest.java:50)
Caused by: java.lang.NumberFormatException: For input string: "''https://jakarta.ee/xml/ns/jaxb''"
    at org.jvnet.jaxb2_commons.xjc.model.concrete.tests.alpha.AlphaMInfoFactoryTest.createModel(AlphaMInfoFactoryTest.java:50)

I managed to fix this unit test by updating the JAXB namespace and version in both the binding.xjb and schema.xsd files:

<jaxb:bindings version="3.0" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc" xmlns:test="urn:test">
<xsd:schema targetNamespace="urn:test" xmlns:test="urn:test"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                        xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
                        elementFormDefault="qualified"
                        attributeFormDefault="unqualified"
                        jaxb:version="3.0"
                        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                        jaxb:extensionBindingPrefixes="xjc">
laurentschoelens commented 7 months ago

This has been done in jaxb-tools v3 and above Thanks for the initial PR

sebersole commented 7 months ago

V3 or v4?

According to https://github.com/highsource/jaxb-tools

The current version 4.X of this plugin supports only JAXB 4.X (Jakarta based).

Versions 2.X and 3.X supports JAXB 2.3 and JAXB 3.0 with JDK8 support and baseline

laurentschoelens commented 7 months ago

@sebersole :

So both v3 and v4 are concerned

Maybe information is clearer on migration guide