JAXB,XJC - >创建多个类文件 [英] JAXB, XJC -> create multiple class files

查看:279
本文介绍了JAXB,XJC - >创建多个类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用JAXB和XJC。

I'm using JAXB and XJC for first time.

我想从XML文件生成Java类,所以我使用这个在线助手从XML文件生成模式。

I would like to generate Java classes from XML file so I use this online helper to generate schema from XML file.

之后我只需使用此命令行生成Java类:

After that I just use this command line to generate Java classes :

xjc myschema.xsd

它的工作原理但我只收到一个Java文件和许多静态类。这可能会生成许多每个文件只包含一个classe的java文件吗?

it's work but I receive only one Java file and many static classes inside it. Is this possible to generate many java files that contain only one classe per file please ?

谢谢

推荐答案

默认 JAXB(JSR-222) 将为嵌套复杂类型创建静态内部类,以防止类名冲突。您可以使用外部绑定文件来禁用此行为。

By default JAXB (JSR-222) will create static inner classes for nested complex types to prevent class name conflicts. You can use an external binding file to disable this behaviour.

binding.xml

绑定文件允许您自定义如何从XML模式生成Java类。

A binding file allows you to customize how Java classes are generated from an XML schema.

<jaxb:bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">
    <jaxb:globalBindings localScoping="toplevel"/>
</jaxb:bindings>

XJC致电

-b 选项与XJC命令一起用于指定绑定文件。

The -b option is used with the XJC command to specify a binding file.

xjc -b binding.xml myschema.xsd

更多信息

  • http://blog.bdoughan.com/2011/07/jaxb-xjc-and-nested-classes.html

这篇关于JAXB,XJC - &gt;创建多个类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆