简体   繁体   English

Maven JAXB-如何指定用于从XSD生成的根节点

[英]Maven JAXB - How to specify root node for generating from XSD

i have a problem. 我有个问题。 I have a really big company XSD file which contains definition of many objects across many systems. 我有一个很大的公司XSD文​​件,其中包含许多系统中许多对象的定义。 I wan't to generate some java classes in my separate project from this XSD but I don't want to generate all classes defined in the XSD because I don't simply need them. 不想在这个XSD的单独项目中生成一些Java类,但是我不想生成XSD中定义的所有类,因为我并不需要它们。

Is it possible to specify something like XSD root node for generating java classes using JAXB in the Maven? 是否可以指定类似XSD根节点的名称,以便在Maven中使用JAXB生成Java类?

I hope my question is clear :) 我希望我的问题很清楚:)

Your question is something I see very often, I would say typical for large bodies of XSD. 您的问题是我经常看到的问题,对于大型XSD,我会说典型的问题。

Unfortunately, I am not aware of a JAXB-way to control the generation process, not the way you want. 不幸的是,我不知道控制生成过程的JAXB方式,而不是您想要的方式。

An alternate solution I've developed for this, hence my bias from this point forward, relies on automatic XML Schema Refactoring (XSR). 为此,我开发了一个替代解决方案,因此,从现在开始,我的偏见依赖于自动XML模式重构(XSR)。 It basically takes in your XSD, and from a set of XSD objects (in your case probably a couple of global elements and maybe some types), it'll generate a subset of XSDs that would only contain the necessary items, no fluff. 它基本上吸收了您的XSD,并从一组XSD对象(在您的情况下可能是几个全局元素,也许还有一些类型)中,将生成XSD的子集,该子集仅包含必要的项目,没有绒毛。 Having those XSDs put through JAXB, it'll give you exactly what you want. 将那些XSD放入JAXB中,它将完全为您提供所需的内容。 This involves QTAssistant, and its XSR functionality. 这涉及QTAssistant及其XSR功能。 The highlevel steps are: 较高级别的步骤是:

  • build a new XSR file; 建立一个新的XSR文件;
  • refer to your source XSDs in an XML Schema Collection 请参考XML模式集合中的源XSD
  • create a "release": a graphical editor helps you with it. 创建一个“版本”:图形编辑器可以帮助您。 Basically, you match the top level XSD objects you want, and the new XSD file locations. 基本上,您可以将所需的顶级XSD对象与新的XSD文件位置进行匹配。
  • Generate the new XSDs. 生成新的XSD。
  • Use the new XSDs with your artifacts. 将新的XSD与工件一起使用。

QTAssistant supports command line integration with Maven through the Exec Maven Plugin , but only on Windows. QTAssistant通过Exec Maven插件支持与Maven的命令行集成,但仅在Windows上。

There is a plugin for generating Java classes that can take XJC arguments, that might be a hook inside more advanced configurations. 有一个用于生成可以带有XJC参数的Java类的插件,这可能是更高级配置中的一个钩子。 But I am not familiar with these. 但是我不熟悉这些。

Taken from the source of the plugin: 取自插件的来源:

/**
 * Space separated string of extra arguments,
 * for instance <code>-Xfluent-api -episode somefile</code>;
 * These will be passed on to XJC as
 * <code>"-Xfluent-api" "-episode" "somefile"</code> options.
 * 
 * @parameter expression="${xjc.arguments}"
 */
protected String arguments;

pom.xml example of the plugin configuration: pom.xml插件配置示例:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
    <execution>
        <id>xjc</id>
        <phase>process-resources</phase>
        <goals>
            <goal>xjc</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <packageName>package.name</packageName>
    <schemaDirectory>${basedir}/src/main/webapp/WEB-INF/xsd</schemaDirectory>
    <bindingDirectory>${basedir}/src/main/java</bindingDirectory>
</configuration>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM