当我生成XSD架构文件时,始终称为schema1.xsd,我如何用注释或?
设置自己的名字@XmlType(namespace = "http://www.xyz.nu/myname")
@XmlRootElement(name = "myname")
public class Myclass {
int id;
...
您可以通过定义SchemaOutputResolver
来指定XSD文件名,如以下代码显示:
public void generate() throws IOException, JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(GlobalConfig.class);
SchemaOutputResolver sor = new MySchemaOutputResolver();
jaxbContext.generateSchema(sor);
}
private class MySchemaOutputResolver extends SchemaOutputResolver {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
File file = new File("your_desired_name.xsd");
StreamResult result = new StreamResult(file);
result.setSystemId(file.toURI().toURL().toString());
return result;
}
}
更多相关:
- jaxb问题列表