this is the first time that I'm using maven-jaxb2-plugin and I'm becoming crazy with this trouble. I have two .xsd schema from which i get two java packages.
This is my maven-jaxb2-plugin configuration
<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>
When i run mvn complie i get two new folder
target/generated-sources/xjc1
|-it.mycompany.jaxb1
|-Dev.java
|-Ea.java
target/generated-sources/xjc2
|-it.mycompany.jaxb2
|-Dev.java
|-Ea.java
Now I'm trying to unmarshall them in this way:
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"));
The trouble is that I'm not able to undestand what
Dev
have to instantiate
it.mycompoany.jaxb1 Dev dev=(EdiL)unmarshaller.unmarshal(new File("myFile.xml"));
it.mycompoany.jaxb2 Dev dev=(EdiL)unmarshaller.unmarshal(new File("myFile.xml"));
I want to manage this in a dinamic way, can you give me any suggestion?