0

这是我第一次使用 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"));

我想以一种动态的方式管理这个,你能给我任何建议吗?

4

0 回答 0