如何告诉jaxb / Maven生成多个架构包? [英] How can I tell jaxb / Maven to generate multiple schema packages?
问题描述
示例:
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/dir1</schemaDirectory>
<schemaIncludes>
<include>schema1.xsd</include>
</schemaIncludes>
<generatePackage>schema1.package</generatePackage>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/dir2</schemaDirectory>
<schemaIncludes>
<include>schema2.xsd</include>
</schemaIncludes>
<generatePackage>schema2.package</generatePackage>
</configuration>
</plugin>
</plugins>
发生了什么:
Maven执行第一个插件。然后删除目标文件夹并创建第二个包,然后可见。
What happened: Maven executes the the first plugin. Then deletes the target folder and creates the second package, which then is visible.
我试图为第一个配置设置target / somedir1,为第二个配置设置target / somedir2 。但这种行为并没有改变?有任何想法吗?我不想直接在src / main / java文件夹中生成包,因为这些包是经过处理的,不应与手动创建的类混合使用。
I tried to set target/somedir1 for the first configuration and target/somedir2 for the second configuration. But the behavior does not not change? Any ideas? I do not want to generate the packages directly in the src/main/java folder, because these packages are genereated and should not be mixed with manual created classes.
推荐答案
我必须指定不同的 generateDirectory
(没有这个,插件正在考虑文件是最新的,并且在第二次执行期间没有生成任何内容)。我建议对生成的源遵循 target / generated-sources /< tool>
约定,以便将它们自动导入您喜欢的IDE中。我还建议声明几个执行
而不是声明插件两次(并在每个<$ c内移动配置
$ c>执行元素):
I had to specify different generateDirectory
(without this, the plugin was considering that files were up to date and wasn't generating anything during the second execution). And I recommend to follow the target/generated-sources/<tool>
convention for generated sources so that they will be imported in your favorite IDE automatically. I also recommend to declare several execution
instead of declaring the plugin twice (and to move the configuration
inside each execution
element):
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/dir1</schemaDirectory>
<schemaIncludes>
<include>shiporder.xsd</include>
</schemaIncludes>
<generatePackage>com.stackoverflow.package1</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
</configuration>
</execution>
<execution>
<id>schema2-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/dir2</schemaDirectory>
<schemaIncludes>
<include>books.xsd</include>
</schemaIncludes>
<generatePackage>com.stackoverflow.package2</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc2</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
使用此设置,我在 mvn clean compile <之后得到以下结果/ code>
With this setup, I get the following result after a mvn clean compile
$ tree target/
target/
├── classes
│ ├── com
│ │ └── stackoverflow
│ │ ├── App.class
│ │ ├── package1
│ │ │ ├── ObjectFactory.class
│ │ │ ├── Shiporder.class
│ │ │ ├── Shiporder$Item.class
│ │ │ └── Shiporder$Shipto.class
│ │ └── package2
│ │ ├── BookForm.class
│ │ ├── BooksForm.class
│ │ ├── ObjectFactory.class
│ │ └── package-info.class
│ ├── dir1
│ │ └── shiporder.xsd
│ └── dir2
│ └── books.xsd
└── generated-sources
├── xjc
│ └── META-INF
│ └── sun-jaxb.episode
├── xjc1
│ └── com
│ └── stackoverflow
│ └── package1
│ ├── ObjectFactory.java
│ └── Shiporder.java
└── xjc2
└── com
└── stackoverflow
└── package2
├── BookForm.java
├── BooksForm.java
├── ObjectFactory.java
└── package-info.java
其中似乎是预期的结果。
Which seems to be the expected result.
这篇关于如何告诉jaxb / Maven生成多个架构包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!