【问题标题】:Automate xjc command to generate Java src files from multiple dtd自动化 xjc 命令以从多个 dtd 生成 Java src 文件
【发布时间】:2015-09-05 16:01:31
【问题描述】:

我正在使用 xjc 从单个 dtd 文件生成基于 JAXB 的 Java 源文件...

尝试使用以下命令行调用时:

xjc -dtd -d . -p com.myapp.jaxb *.dtd 

我收到此错误消息:

parsing a schema...
[ERROR] Too many schema files for this schema language. Compile one file at a time.
unknown location

Failed to parse a schema.

有没有办法(通过 Unix shell 脚本)自动生成多个 dtd 文件?

如果 Unix shell 脚本可以遍历目录中的整个 dtds 列表,那就太好了。

另外,这样做(自动化 xjc)会对 ObjectFactory 类产生负面影响吗?

感谢您花时间阅读本文...

【问题讨论】:

  • 也许使用 maven jaxb2 插件
  • 谢谢 MGorgon,为什么这被标记为 -1 ?
  • @MGorgon 不,无济于事。它仍然是集线器下的 XJC,所以你会得到同样的“Too many schema files”错误。
  • @socal_javaguy -1 (不是来自我)可能是“如果 Unix shell 脚本可以遍历目录中的整个 dtds 列表会很好”。您在这里基本上是在说“请为我完成我的工作,给我写一个脚本”。

标签: shell unix jaxb dtd xjc


【解决方案1】:

我通常在编译之前先在一个文件中连接 DTD。例如,maven-antrun-plugin:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>concatenate-dtds</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <target>
                            <concat destfile="src/main/resources/ogc/wms/1.1.0/wms_1_1_0.dtd">
                                <fileset dir="src/main/resources/ogc/wms/1.1.0" includes="capabilities*.dtd,exception*.dtd"/>
                            </concat>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
                <execution>
                    <phase>process-sources</phase>
                    <configuration>
                        <target>
                            <delete dir="${basedir}/target/generated-sources/xjc/WMS_1_1_0"/>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

编译多个 DTD 的真实项目示例:

https://github.com/highsource/ogc-schemas/blob/master/wms/1.1.0/pom.xml#L43-L71

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多