java如何从XSD生成JAXB类?
我对XML完全是个新手。我正在做一个JavaEE项目REST实现,我们返回了大量XML。有了这个,我们决定使用JAXB。到目前为止,我们为XML手动编写了模型
但是已经有了这些复杂的结构,我们不知道如何编码。我们已经读过关于从XSD生成类的内容。我们有一个XSD
我的问题是:
1.)我读过关于XJC的书,在哪里可以找到
2.)我们必须安装整个JAXB吗?(到目前为止我们使用了什么?这不是JAXB吗?)
你可以在下面搜索框中键入要查询的问题!
我对XML完全是个新手。我正在做一个JavaEE项目REST实现,我们返回了大量XML。有了这个,我们决定使用JAXB。到目前为止,我们为XML手动编写了模型
但是已经有了这些复杂的结构,我们不知道如何编码。我们已经读过关于从XSD生成类的内容。我们有一个XSD
我的问题是:
1.)我读过关于XJC的书,在哪里可以找到
2.)我们必须安装整个JAXB吗?(到目前为止我们使用了什么?这不是JAXB吗?)
# 1 楼答案
cxf对这类东西有很好的支持
# 2 楼答案
对于EclipseST(至少3.5版)您不需要安装任何东西右键单击模式。xsd->;生成->;JAXB类您必须指定软件包&;在下一步中,仅此而已,应该生成您的类。我想上面提到的所有解决方案都有效,但这似乎是迄今为止最简单的(对于STS用户)
[更新]Eclipse STS 3.6版(基于开普勒)也有相同的功能
# 3 楼答案
如果您正在使用Eclipse,还可以尝试JAXB Eclipse Plug-In
您可以在这里找到关于jdk安装附带的XJC绑定编译器的更多信息:XJC:Java™ Architecture for XML Binding -Binding Compiler
我希望这有帮助
# 4 楼答案
XJC包含在JDK的bin目录中,从JavaSE6开始。有关示例,请参见:
博客内容如下:
使用JAXB处理Atom提要 Atom是一种表示web提要的XML格式。标准格式允许阅读器应用程序显示来自不同来源的提要。在这个例子中,我们将处理这个博客的Atom提要
演示
在本例中,我们将使用JAXB将与此博客对应的Atom XML提要转换为对象,然后再转换回XML
JAXB模型
以下模型由schema to Java编译器(XJC)生成。为了节省空间,我省略了get/set方法和注释
包裹信息
类别类型
内容类型
日期时间类型
入口类型
饲料型
生成器类型
iCountype
IdType
链接类型
标识
人格类型
源类型
文本类型
尿酸型
# 5 楼答案
1)您可以使用标准java实用工具xjc-([your java home dir]\bin\xjc.exe)。但你需要创造。使用它的bat(或.sh)脚本
例如生成。蝙蝠:
例如,测试方案。xsd:
快跑。带参数的bat文件:生成。bat测试方案。xsd-d[你的src目录]
有关更多信息,请使用本文档-http://docs.oracle.com/javaee/5/tutorial/doc/bnazg.html
而这个http://docs.oracle.com/javase/6/docs/technotes/tools/share/xjc.html
2)默认情况下,JAXB(xjc实用程序)与JDK6一起安装