2016-04-20 39 views
0

我正在创建一个非java的Maven工件。在pom.xml中,我解决了一些依赖关系,然后使用exec插件运行自定义脚本。有些文件是在一个目录中创建的,但Maven在将它们打包到jar中时看不到它们。Maven包只包含第二次运行的文件

当我运行mvn package两次时,第二次运行确实包含jar中的资源文件。

任何想法为什么会发生这种情况?该脚本在compile阶段运行,因此在package阶段创建jar时已创建文件。


这是我pom.xml配置的相关(希望)部分:

<plugins> 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.4.0</version> 
     <executions> 
      <execution> 
       <id>build-plugin</id> 
       <phase>compile</phase> 
       <goals> 
        <goal>exec</goal> 
       </goals> 
       <configuration> 
        <executable>bash</executable> 
        <arguments> 
         <argument>build_plugin.sh</argument> 
         <argument>${workspace}</argument> 
         <argument>${plugin}</argument> 
        </arguments> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 

<resources> 
    <resource> 
     <directory>${project.basedir}/${outputPath}</directory> 
     <includes> 
      <include>**</include> 
     </includes> 
     <excludes> 
      <exclude>target/**</exclude> 
     </excludes> 
    </resource> 
</resources> 

所有的变量和路径是有效的,对我越来越有预期的内容的罐子第二轮。但不是在第一次。

回答

1

Maven中默认的生命周期资源的处理编译 看到https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

之前发生了,你所要做的就是改变“的exec-Maven的插件”的构建阶段,用什么“产生来源”,而不是“编译”

<plugins> 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.4.0</version> 
     <executions> 
      <execution> 
       <id>build-plugin</id> 
       <phase>generate-sources</phase> 
       <goals> 
        <goal>exec</goal> 
       </goals> 
       <configuration> 
        <executable>bash</executable> 
        <arguments> 
         <argument>build_plugin.sh</argument> 
         <argument>${workspace}</argument> 
         <argument>${plugin}</argument> 
        </arguments> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 

<resources> 
    <resource> 
     <directory>${project.basedir}/${outputPath}</directory> 
     <includes> 
      <include>**</include> 
     </includes> 
     <excludes> 
      <exclude>target/**</exclude> 
     </excludes> 
    </resource> 
</resources> 
相关问题