如何管理多个架构maven-jaxb2-plugin

时间:2014-03-12 12:24:39

标签: java maven maven-jaxb2-plugin

这是我第一次使用maven-jaxb2-plugin而且我对这个问题变得疯狂。 我有两个.xsd架构,我可以从中获得两个java包。

这是我的maven-jaxb2-plugin配置

<plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.1</version>

        <executions>
            <execution>
                <id>schema1-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>

                    <configuration>
                        <systemPropertyVariables>
                            <user.language>en</user.language>
                            <user.region>GB</user.region>
                        </systemPropertyVariables>
                        <schemaDirectory>src/main/resources/myPath/schema</schemaDirectory>
                            <schemaIncludes>
                                <include>schema1.xsd</include>
                        </schemaIncludes>
                        <generatePackage>it.mycompany.jaxb1</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
                        <readOnly>true</readOnly>
                    </configuration>
            </execution>
            <execution>
                <id>schema2-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>

                    <configuration>
                        <systemPropertyVariables>
                            <user.language>en</user.language>
                            <user.region>GB</user.region>
                        </systemPropertyVariables>
                        <schemaDirectory>src/main/resources/myPath/schema</schemaDirectory>
                            <schemaIncludes>
                                <include>schema2.xsd</include>
                        </schemaIncludes>
                        <generatePackage>it.mycompany.jaxb2</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/xjc12</generateDirectory>
                        <readOnly>true</readOnly>
                    </configuration>
            </execution>
        </executions>
    </plugin>

当我运行mvn complie时,我得到两个新文件夹

target/generated-sources/xjc1
    |-it.mycompany.jaxb1
        |-Dev.java
        |-Ea.java


target/generated-sources/xjc2
    |-it.mycompany.jaxb2
        |-Dev.java
        |-Ea.java

现在我正试图以这种方式取消它们:

String schemaChhosed = "pathSchemaChoosed"
String packageNameChoosed = "packageNameChoosed"    

JAXBContext jc = null;  
Unmarshaller unmarshaller =null;

jc = JAXBContext.newInstance("packageNameChoosed");
unmarshaller=jc.createUnmarshaller();

Schema schema1 = sf.newSchema(new File("pathSchemaChoosed"));
Dev dev=(EdiL)unmarshaller.unmarshal(new File("myFile.xml"));

麻烦的是我无法理解

  

开发

必须实例化

it.mycompoany.jaxb1 Dev dev=(EdiL)unmarshaller.unmarshal(new File("myFile.xml"));
it.mycompoany.jaxb2 Dev dev=(EdiL)unmarshaller.unmarshal(new File("myFile.xml"));

我想以恐怖的方式管理这个,你能给我任何建议吗?

0 个答案:

没有答案