2

我需要为一堆 Java 类构建一个 XML 模式。我尝试使用 JAXB (schemagen) 和 JIBX (bindgen)。我的 java 类从库中的一个类扩展,并包含几个继承和子类。

JAXB失败 1:我得到了异常JAXB can't handle interfaces。我的类没有任何注释,也没有 .jar 文件中的扩展类。

public class MySchemaOutputResolver extends SchemaOutputResolver {
    public static void main(String[] args) throws IOException, JAXBException {    
        JAXBContext jaxbContext = JAXBContext.newInstance(MYCLASS.class);
        jaxbContext.generateSchema(new MySchemaOutputResolver(filepath));
    }

    String filepath = null;
    public MySchemaOutputResolver(String filepath)  {
        this.filepath = filepath;
    }

    @Override
    public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
        File file = new File(filepath);
        StreamResult result = new StreamResult(file);
        result.setSystemId(file.toURI().toURL().toString());
        return result;
    }
} 

失败2:然后我尝试使用JIBX(bindgen)。但是这里的输出只包含当前类的值。不会创建扩展类中的所有变量。

所以也许我很基本地问了这个问题:

如何创建一个 XML Schema,其中包含来自 Java 类的所有属性,该 Java 类从 .jar 扩展另一个类?

4

0 回答 0