JAXB Maven 使用多个剧集生成 类

JAXB Maven generate classes using multiple episodes

使用 this maven plugin,我能够生成我的 类 并在另一个模式中重复使用它们;这真的很棒!

现在我发现自己有一个需要两集的模式(从模式生成的两个不同的包)。我只是想在 XJC 中添加另一个 arg,但它没有用。

然后我改变了两个参数的顺序,错误针对的是另一个模式。后来我才明白,两集都可以,但未必是做事的方式。

这是我的一些 pom:

<execution>
    <id>business</id>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
      ..
      <extension>true</extension>
      <args>
        <arg>-b</arg>
        <arg>${project.basedir}/target/episodes/x.episode</arg>
        <arg>${project.basedir}/target/episodes/y.episode</arg>
        <arg>${project.basedir}/target/episodes/z.episode</arg>
      </args>
      ..
    </configuration>
</execution>

这是我得到的:

org.xml.sax.SAXParseException; systemId: file:/****.episode;行号:2;列数:65; s4s-elt-schema-ns:命名空间元素 'bindings' 必须来自“http://ww.w3.org/2001.XMLSchema”。

据我了解(调换他们的调用后),三个 schemas/episodes 都不错,但我不能同时使用它们。有什么办法吗?

这里是新手,非常感谢任何帮助:)。

我以前在另一个项目上做过这个。我认为您使用了错误的语法:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>jaxb-Generic-XSD</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <enableIntrospection>false</enableIntrospection>
                <schemaFiles>Generic.xsd</schemaFiles>
                <schemaDirectory>${jaxb.schema.folder}</schemaDirectory>
                <packageName>you.package.name.here</packageName>
                <outputDirectory>${jaxb.output.folder}</outputDirectory>
                <extension>true</extension>
                <arguments>-b ${core.episode.file} -b ${containers.episode.file}</arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

注意:<arguments>-b ${core.episode.file} -b ${containers.episode.file}</arguments> 行。

我认为您使用的是相同的 maven 插件,但如果不是,请记下插件版本 groupId、artifactId,并改用它。

的作者在这里。

为什么要使用 args,为什么不直接在配置中添加剧集?

<episodes>
    <episode>
        <groupId>com.acme.foo</groupId>
        <artifactId>package1</artifactId>
        <!-- Version is not required if the artifact is
            configured as dependency -->
    </episode>
    <episode>
        <groupId>com.acme.foo</groupId>
        <artifactId>package2</artifactId>
        <!-- Version is not required if the artifact is
            configured as dependency -->
    </episode>
</episodes>

episode 的整体思路是,您可以指向 JAR(包含 episode 文件),XJC 将从包含的 episode 中找出并使用绑定。将 arg-b 一起使用并不是它的目的。 :)

关于您看到的错误,我猜您配置 arg 的方式让 XJC 认为您的第二集和更多集实际上是模式。我会尝试将中间 -b 参数或配置您在一个 arg.

中引用的所有剧集

但我仍然认为这不是使用剧集的正确方法。将您的剧集编译为单独的 JARs/separate Maven 模块,将它们用作依赖项并将它们配置为 episodes 或仅打开 useDependenciesAsEpisodes 选项。