这个问题与 maven: How to add resources which are generated after compilation phase 中提出的解决方案完全相同,但我正在寻找另一种解决方案。
在我的插件中,我成功地在 target/generated-resources/some
目录中生成了一些资源文件。
现在我希望将这些资源文件包含在托管项目的最终 jar 中。
我试过了。
final Resource resource = new Resource();
resource.setDirectory("target/generated-resources/some");
project.getBuild().getResources().add(resource);
其中
project
是这样定义的。@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
它不起作用。
最佳答案
在编译阶段之后,不再调用 Maven 资源插件。因此,在如此晚的阶段为构建添加更多资源只会产生装饰效果,例如Eclipse 等 IDE 将 generate-resources 文件夹识别为源文件夹并进行相应标记。
您必须手动将结果从插件复制到构建输出文件夹:
import org.codehaus.plexus.util.FileUtils;
// Finally, copy all the generated resources over to the build output folder because
// we run after the "process-resources" phase and Maven no longer handles the copying
// itself in later phases.
try {
FileUtils.copyDirectoryStructure(
new File("target/generated-resources/some"),
new File(project.getBuild().getOutputDirectory()));
}
catch (IOException e) {
throw new MojoExecutionException("Unable to copy generated resources to build output folder", e);
}
关于maven - 插件如何添加自己生成的资源?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33166295/