gpt4 book ai didi

maven-2 - 如何告诉 jaxb/Maven 生成多个模式包?

转载 作者:IT老高 更新时间:2023-10-28 11:53:26 25 4
gpt4 key购买 nike

例子:

</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 执行第一个插件。然后删除目标文件夹并创建第二个包,然后可见。

我尝试为第一个配置设置 target/somedir1,为第二个配置设置 target/somedir2。但行为没有改变?有任何想法吗?我不想直接在 src/main/java 文件夹中生成包,因为这些包是生成的,不应该与手动创建的类混合。

最佳答案

我必须指定不同的 generateDirectory (没有这个,插件认为文件是最新的,并且在第二次执行期间没有生成任何东西)。我建议关注 target/generated-sources/<tool>生成源的约定,以便它们将自动导入您喜欢的 IDE。我还建议声明几个execution而不是两次声明插件(并在每个 configuration 元素中移动 execution):

<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 之后得到以下结果

$ 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

这似乎是预期的结果。

关于maven-2 - 如何告诉 jaxb/Maven 生成多个模式包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2857081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com