I am using Gradle to generate jaxb classes in my project. Every thing is working fine but while marshalling the jaxb object we are seeing different namespaces prefixes like ns1, ns2 .. randomly in the output xml. But we dont want this and want to specify specific namespace prefixes for each namespace. I checked here and found the link 15772478 saying we have to have package-info class with xmlns element, How can i say to xjc binding compiler to add xmlns element with prifixes and namespaceURI? below is the gradle configuration i have to generate Jaxb classes from schemas.
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath:configurations.jaxb.asPath)
ant.jaxbTargetDir = jaxbTargetDir
ant.xjc(destdir: '${jaxbTargetDir}', binding: 'xjc-bindings/bindings.jaxb', extension: true) {
//arg(value: '-npa')
arg(value: '-readOnly')
arg(value: file('src/main/webapp/schemas/primary1.xsd'))
arg(value: file('src/main/webapp/schemas/primary2.xsd'))
arg(value: file('xjc-bindings/xjc-a.xsd'))
arg(value: file('xjc-bindings/xjc-b.xsd'))
}
sample package-info.java generated by xjc binding.
@XmlSchema(namespace = "urn:neustar:names:decedm:1.0")
package biz.neustar.dece.xml.jaxb.decedm;
import javax.xml.bind.annotation.XmlSchema;
I am expecting the package-info class like below.
@XmlSchema(namespace = "<someuri>",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns={
@XmlNs(prefix="someprefix" , namespaceURI = "<some uri>")
})
package biz.neustar.dece.xml.jaxb.core;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;
Can somebody please suggest me what is the configuration need to achieve this? I don't want to use NamespacePrefixMapper to specify the prefixes.