0

I am trying to generate xsd out of java objects that are annotated with jaxb annotations. When executing the schemagen its generating xsd but it doesnt rename it and no namespace exists. During maven install execution, I see an warning from the plugin

[INFO] XSD post-processing: Renaming and converting XSDs.
[WARNING] SimpleNamespaceResolver contained no localNamespaceURI; aborting rename.

while debugging the jaxb2-maven plugin code, its trying to search namespace in the generated xml and I dont see that either. So namespace given in java classes are not translating to XSDs. Here is pom.xml and java classes and generated xsds for reference

I have looked into couple of posts before posting question, but none of the solutions work.

link1 link2 link3

pom.xml

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>schemagen</id>
            <goals>
                <goal>schemagen</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <sources>
                    <source>
                        ${project.basedir}\src\main\java\com\example\o\tools\overridesscanner\xsd\beans\</source>
                </sources>
                <quiet>true</quiet>
                <sources>
                    <source>
                        ${project.basedir}\src\main\java\com\example\o\tools\overridesscanner\xsd\beans\Release.java</source>
                    <source>
                        ${project.basedir}\src\main\java\com\example\o\tools\overridesscanner\xsd\beans\Root.java</source>
                </sources>
                <transformSchemas>
                    <transformSchema>
                        <uri>http://www.example.com/2023/08/31/releases</uri>
                        <toPrefix>some</toPrefix>
                        <toFile>some_schema.xsd</toFile>
                    </transformSchema>
                </transformSchemas>
                <outputDirectory>${project.basedir}\src\main\resources\schemas</outputDirectory>
                <clearOutputDir>true</clearOutputDir>
            </configuration>
        </execution>
    </executions>
</plugin>

Generated xsd with name schema1.xsd

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">

    <xs:complexType name="release">
        <xs:sequence>
            <xs:element minOccurs="0" name="parentReleaseName" type="xs:string" />
            <xs:element minOccurs="0" name="parentReleasePath" type="xs:string" />
            <xs:element minOccurs="0" name="releaseName" type="xs:string" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="root">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="releases" nillable="true"
                type="release" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Classes annotated with jaxb annotations

package-info.java

@XmlSchema(namespace = "http://www.example.com/2023/08/31/releases")
package com.example.o.tools.overridesscanner.xsd.beans;
import javax.xml.bind.annotation.XmlSchema;

Root.java

@XmlRootElement(name = "root", namespace = "http://www.example.com/2023/08/31/releases")
@XmlType(namespace = "http://www.example.com/2023/08/31/releases")
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {

    public List<Release> getReleases() {
        return releases;
    }

    public void setReleases(List<Release> releases) {
        this.releases = releases;
    }

    private List<Release> releases;

}

Release.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "http://www.example.com/2023/08/31/releases")
public class Release {

    @XmlElement(name = "releaseName")
    private String releaseName;
    @XmlElement(name = "parentReleaseName")
    private String parentReleaseName;
    @XmlElement(name = "parentReleasePath")
    private String parentReleasePath;

    public String getReleaseName() {
        return releaseName;
    }

    public void setReleaseName(String releaseName) {
        this.releaseName = releaseName;
    }

    public String getParentReleaseName() {
        return parentReleaseName;
    }

    public void setParentReleaseName(String parentReleaseName) {
        this.parentReleaseName = parentReleaseName;
    }

    public String getParentReleasePath() {
        return parentReleasePath;
    }

    public void setParentReleasePath(String parentReleasePath) {
        this.parentReleasePath = parentReleasePath;
    }

}
zforgo
  • 2,508
  • 2
  • 14
  • 22
Rajan
  • 124
  • 2
  • 12

0 Answers0