使用jaxb和maven在不同的包中生成类

时间:2012-03-01 14:28:15

标签: maven-2 pom.xml jaxb2 maven-jaxb2-plugin

这个问题与this one非常相似,但我的情况有点不同

我有一个包含许多xsd和wsdl的目录。其中一些需要生成不同的包。

我已将pom.xml配置如下:

    <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.7.1</version>
            <executions>
                <execution>
                    <id>xsd-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generateDirectory>${project.build.directory}/generated-sources/xsdClasses</generateDirectory>
                        <generatePackage>eu.ist_phosphorus.harmony.common.serviceinterface.databinding.jaxb</generatePackage>
                        <schemaDirectory>resources/webservices</schemaDirectory>
                        <includeSchemas>
                            <!-- we have 3 top level xsd's -->
                            <include>Topology-Types.xsd</include>
                            <include>Reservation-Types.xsd</include>
                            <include>Notification-Types.xsd</include>

                        </includeSchemas>
                        <extension>true</extension>
                        <args>
                            <arg>-Xcopyable</arg> <!-- to make them implement java.lang.Cloneable -->
                        </args>
                        <plugins>
                            <!-- necesary for -Xcopyable to work -->
                            <plugin>
                                <groupId>org.jvnet.jaxb2_commons</groupId>
                                <artifactId>jaxb2-basics</artifactId>
                                <version>0.5.3</version>
                            </plugin>
                        </plugins>
                    </configuration>
                </execution>

                <execution>
                    <id>wsdl-reservation-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generateDirectory>${project.build.directory}/generated-sources/reservationClasses</generateDirectory>
                        <generatePackage>eu.ist_phosphorus.harmony.common.serviceinterface.reservation</generatePackage>
                        <schemaDirectory>resources/webservices/</schemaDirectory>
                        <includeSchemas>
                            <include>Reservation-WS.wsdl</include>
                        </includeSchemas>
                        <extension>true</extension>
                    </configuration>
                </execution>

                <execution>
                    <id>wsdl-notification-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generateDirectory>${project.build.directory}/generated-sources/notificationClasses</generateDirectory>
                        <generatePackage>eu.ist_phosphorus.harmony.common.serviceinterface.notification</generatePackage>
                        <schemaDirectory>resources/webservices</schemaDirectory>
                        <includeSchemas>
                            <include>Notification-WS.wsdl</include>
                        </includeSchemas>
                        <extension>true</extension>
                    </configuration>
                </execution>

                <execution>
                    <id>wsdl-topology-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generateDirectory>${project.build.directory}/generated-sources/topologyClasses</generateDirectory>
                        <generatePackage>eu.ist_phosphorus.harmony.common.serviceinterface.topology</generatePackage>
                        <schemaDirectory>resources/webservices</schemaDirectory>
                        <includeSchemas>
                            <include>Topology-WS.wsdl</include>
                        </includeSchemas>
                        <extension>true</extension>
                    </configuration>
                </execution>

            </executions>

        </plugin>

当我运行mvn编译时,生成了类,问题是每个生成的包都包含每个类,而不仅仅是包含了includeSchemas的类。

如何配置插件,以便每个包只包含includeSchemas中列出的类?

为什么我的案子与另一个问题不同?我不能将xsd / wsdl文件放在不同的目录中,因为它们依赖于额外的文件,我认为这不是一个好主意复制

1 个答案:

答案 0 :(得分:1)

我认为您的问题是<includeSchemas>应为<schemaIncludes>(至少版本为0.8.0)