JAXB混合剧集和jar库中的xjc:javaType

时间:2012-09-27 11:40:39

标签: java maven-2 jaxb jaxb2 jaxb-episode

如果得到了其他项目所依赖的Java库(.jar依赖于Maven)。在这个库中有一个XSD文件,它定义了一些xs:simpleType,它们也用xjc:javaType元素注释,将简单类型映射到该库中已有的java类和适配器类。这一切都很好,但现在我想创建一个xs:complexType。我让org.jvnet.jaxb2.maven2:maven-jaxb2-plugin版本0.8.2从复杂类型和附加.episode文件创建一些java bean。

在我的第二个项目中,我导入了库,将xsd文件解压缩到一个模式目录中,让project2.xsd导入library.xsd,因为它使用了简单和复杂的类型。为避免重复生成已存在的bean,我在episodes的{​​{1}}标记中添加了libary作为依赖项。但现在插件抱怨它无法解析xsd文件并在每个类型的定义行上抛出异常。

我认为使用剧集(它们不包括simpleTypes?)和org.jvnet.jaxb2.maven2:maven-jaxb2-plugin注释存在一些问题?这个问题有某种解决方法吗?关于这个问题我在网上找不到多少。感谢任何提示。

1 个答案:

答案 0 :(得分:1)

我通过使用maven-hyperjaxb3-plugin实现了同样的目标 检查完成情况:

            <plugin>
                <groupId>org.jvnet.hyperjaxb3</groupId>
                <artifactId>maven-hyperjaxb3-plugin</artifactId>
                <version>0.5.4</version>
                <executions>
                <execution>
                    <id>id1</id>
                    <inherited>false</inherited>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <args>
                            <param>-npa</param>
                        </args>
                        <generateDirectory>target/generated-sources/xjc2</generateDirectory>
                        <generatePackage>com.target.package</generatePackage>
                        <extension>true</extension>
                        <schemaIncludes>
                            <include>mine.xsd</include>
                        </schemaIncludes>
                        <forceRegenerate>false</forceRegenerate>
                        <removeOldOutput>true</removeOldOutput>
                        <verbose>true</verbose>
                    </configuration>
                </execution>
</executions>
<dependencies>
                    <dependency>
                        <groupId>com.sun.xml.bind</groupId>
                        <artifactId>jaxb-impl</artifactId>
                        <version>2.1.12</version>
                    </dependency>
                </dependencies>
            </plugin>

这是项目依赖项:

<dependencies>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1.12</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>org.jvnet.hyperjaxb3</groupId>
            <artifactId>hyperjaxb3-ejb-runtime</artifactId>
            <version>0.3</version>
        </dependency>

        <!-- Roundtrip -->
        <dependency>
            <groupId>org.jvnet.hyperjaxb3</groupId>
            <artifactId>hyperjaxb3-ejb-roundtrip
            </artifactId>
            <version>0.3</version>
        </dependency>
    </dependencies>

我定义了任何类型的简单和复杂类型,它就像一个魅力。 希望它有所帮助!