實際上,你可以使用驅動程序類(com.sun.tools.xjc.Driver)命令行工具落後。這對我有效:
import com.sun.tools.xjc.BadCommandLineException;
import com.sun.tools.xjc.Driver;
import com.sun.tools.xjc.XJCListener;
import org.xml.sax.SAXParseException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Generator {
public static void main(String[] args) throws BadCommandLineException, IOException {
final String targetDir = "jaxb-files";
Path path = Paths.get(targetDir);
if(!Files.exists(path)) {
Files.createDirectories(path);
}
Driver.run(new String[]{"-d", targetDir,
"D:\\dev\\onepoint\\tui\\java\\xsdjsonschema\\src\\main\\xsd\\test.xsd"}, new XJCListener() {
@Override
public void error(SAXParseException e) {
printError(e, "ERROR");
}
@Override
public void fatalError(SAXParseException e) {
printError(e, "FATAL");
}
@Override
public void warning(SAXParseException e) {
printError(e, "WARN");
}
@Override
public void info(SAXParseException e) {
printError(e, "INFO");
}
private void printError(SAXParseException e, String level) {
System.err.printf("%s: SAX Parse exception", level);
e.printStackTrace();
}
});
}
}
我也試過這也..問題是,它永遠不會退出此也!那是因爲這個過程永遠不會結束! – leet
這對我來說效果很好 – Ilya