I want to generate an XSD file from a Java file using the JAXB2 Maven plugin. But JAXB generates a file that ignores the names specified in the @XmlElement annotations and does not rename the file. Instead it just says "[WARNING] SimpleNamespaceResolver contained no localNamespaceURI; aborting rename.".
My Java class looks like this:
package com.my.testpackage;
import java.util.List;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
namespace = "https://my.test.domain",
propOrder = {
"Entries"
})
@XmlRootElement(
namespace = "https://my.test.domain",
name = "TestXmlClass"
)
public class TestXmlClass {
@XmlElement(name = "Entries")
protected List<String> entries;
public List<String> getEntries() {
return entries;
}
public TestXmlClass setEntries(List<String> entries) {
this.entries = entries;
return this;
}
}
The package-info.java looks like this:
@XmlSchema(namespace = "https://my.test.domain")
package com.my.testpackage;
import javax.xml.bind.annotation.XmlSchema;
The Maven plugin config looks like this:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>src/main/java/com/my/testpackage/TestXmlClass.java
</source>
</sources>
<transformSchemas>
<transformSchema>
<uri>https://my.test.domain</uri>
<toFile>my-xsd-file.xsd</toFile>
</transformSchema>
</transformSchemas>
</configuration>
</plugin>
...
The output is named schema1.xsd and not my-xsd-file.xsd and it writes the element names in lower case instead of upper case and it ignores the namespace from the Java annotations:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="testXmlClass">
<xs:sequence>
<xs:element name="entries" type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
What am I missing?