maven:如何添加编译阶段后生成的资源 [英] maven: How to add resources which are generated after compilation phase
问题描述
我有一个maven项目,它使用wsgen从已编译的java类生成xsd文件。
问题是我想将生成的xsd文件作为资源添加到jar中。
b $ b由于资源阶段在进程类阶段之前运行,我无法添加它们。
有没有办法在进程类阶段之后添加额外的资源?
I have a maven project which uses wsgen to generate xsd files from the compiled java classes.
The problem is that I want to add the generated xsd files to the jar as resources.
Since the resource phase is running before the "process-classes" phase I can't add them.
Is there a way to add additional resource after the "process-classes" phase?
推荐答案
我建议将XSD文件的输出目录定义为目标/类(可能是一个补充子文件夹,它将是稍后在包装阶段打包到jar中。这可以通过使用 maven-resources来实现。 -plugin 。
I would suggest to define the output directory for the XSD files into target/classes (may be with a supplemental sub folder which will be packaged later during the package phase into the jar. This can be achieved by using the maven-resources-plugin.
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/xsd-out</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
您需要注意资源插件位于用于调用wsgen的插件之后部分。您也可以使用 prepare-package 阶段来确保资源正确打包。
You need to take care that the resources plugin is positioned after the plugin which is used to call the wsgen part. You can also use the prepare-package phase instead to make sure the resources will be correctly packaged.
这篇关于maven:如何添加编译阶段后生成的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!