2016-04-20 41 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> 
相關問題