答案 0 :(得分:2)
你可能很容易写一些东西,然后从Ant调用它:
import java.io.File;
import java.io.IOException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
public class SchemaGenerator {
public static void main(String[] args) throws Exception {
String contextPath = args[0];
String outputDir = args[1];
JAXBContext jc = JAXBContext.newInstance(contextPath);
jc.generateSchema(new MySchemaOutputResolver(schemaFileName));
}
private static class MySchemaOutputResolver extends SchemaOutputResolver {
private String outputDir;
public MySchemaOutputResolver(String outputDir) {
this.outputDir = outputDir;
}
public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
File file = new File(outputDir + "/" + suggestedFileName);
StreamResult result = new StreamResult(file);
result.setSystemId(file.toURI().toURL().toString());
return result;
}
}
}
在您的上下文路径中,您需要一个jaxb.index文件,其中包含要包含在JAXBContext中的类列表。或者您可以将类名传递给SchemaGenerator类并通过ClassLoader加载它们。