Maven 插件如何添加自己生成的资源?

Maven 插件如何添加自己生成的资源?,maven,maven-plugin,Maven,Maven Plugin,这个问题与中所问的完全相同,但我正在寻找另一个解决方案 在我的插件中,我成功地在target/generated resources/some目录中生成了一些资源文件 现在我希望这些资源文件包含在托管项目的最终jar中 我试过了 final Resource Resource=new Resource(); setDirectory(“目标/生成的资源/some”); project.getBuild().getResources().add(资源); 其中,项目的定义如下 @参数(defau

这个问题与中所问的完全相同,但我正在寻找另一个解决方案

在我的插件中,我成功地在
target/generated resources/some
目录中生成了一些资源文件

现在我希望这些资源文件包含在托管项目的最终jar中

我试过了

final Resource Resource=new Resource();
setDirectory(“目标/生成的资源/some”);
project.getBuild().getResources().add(资源);
其中,
项目
的定义如下

@参数(defaultValue=“${project}”,readonly=true,required=true)
私人马文项目;

编译阶段结束后,Maven资源插件不再被调用。因此,在这样一个后期阶段向构建添加更多资源只会产生表面效果,例如,Eclipse之类的IDE将生成的资源文件夹识别为源文件夹,并相应地对其进行标记

您必须手动将结果从插件复制到生成输出文件夹:

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);
}

尝试调用
project.addResource(resource)取而代之。