2015-02-04 30 views
3

希望一些jar文件内的文件复制到我的java项目的根文件夹中。不要在maven-dependency-plugin解压缩目标中重现路径

我用这个:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>unpack</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>unpack</goal> 
        </goals> 
        <configuration> 
         <artifactItems> 
          <artifactItem> 
          <groupId>net.sourceforge.tess4j</groupId> 
          <artifactId>tess4j</artifactId> 
          <version>1.4.1</version> 
          <type>jar</type> 
          <includes>win32-x86/*.dll</includes> 
          <overWrite>true</overWrite> 
          <outputDirectory>${basedir}</outputDirectory> <!-- project root directory --> 
         </artifactItem> 
         </artifactItems> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

问题是,我得到这个

javaProject 
    src 
    target 
    win32-x86/dll1.dll 
    win32-x86/dll2.dll 

我想这

javaProject 
    src 
    target 
    dll1.dll 
    dll2.dll 

我不想从里面的文件夹路径jar被转载,我只想把这些文件转储到我的项目的根目录中。

任何想法?

谢谢。

回答

2

可以使用Jetspeed的解压Maven插件:http://pulkitsinghal.blogspot.be/2011/04/jetspeed-finally-unpack-plugin-with.html

http://portals.apache.org/jetspeed-2/buildguide/jetspeed-unpack-plugin.html相关文档。

你想要的选项是:

<flat>true</flat> 

完整的示例:

<plugin> 
    <groupId>org.apache.portals.jetspeed-2</groupId> 
    <artifactId>jetspeed-unpack-maven-plugin</artifactId> 
    <version>${org.apache.portals.jetspeed.version}</version> 
    <configuration> 

    <unpack> 
     <artifact>...</artifact> 
     <file>...</file> 
     <targetDirectory>...</targetDirectory> 
     <overwrite>...</overwrite>    
     <resources combine.children="append"> 

     <resource> 
      <path>...</path> 
      <destination>...</destination> 
      <overwrite>...</overwrite> 
      <flat>...</flat> 
      <include>...</include> 
      <exclude>...</exclude> 
      <name>...</name> 
     </resource> 
     ... 
     </resources> 
    </unpack> 

    <skip>...</skip> 
    <verbose>...</verbose> 

    </configuration> 
</plugin> 
+0

完美谢谢:D – Eildosa

+3

20行XML,我可以用2行bash脚本完成此操作:( 甚至不能使它工作:( 我讨厌maven。 –

0

您可以使用

 <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>test-compile</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <tasks> 
        <move todir="${libPath}"> 
         <fileset dir="${libPath}"/> 
         <mapper type="flatten"/> 
        </move> 
       </tasks> 
      </configuration> 
     </plugin> 

事后扁平化的结果。

相关问题