在maven依赖插件解包目标期间不复制路径

在maven依赖插件解包目标期间不复制路径,maven,maven-3,unpack,maven-dependency-plugin,Maven,Maven 3,Unpack,Maven Dependency Plugin,我想把jar中的一些文件复制到我的java项目的根文件夹中 我用了这个: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <

我想把jar中的一些文件复制到我的java项目的根文件夹中

我用了这个:

<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
    dll1.dll
    dll2.dll
我不想复制jar中的文件夹路径,我只想将文件转储到项目的根目录中

有什么想法吗


谢谢。

您可以使用Jetspeed unpack maven插件:

有关文档,请参阅

您需要的选项是:

<flat>true</flat>
true
完整示例:

<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>

org.apache.portals.jetspeed-2
jetspeed解包maven插件
${org.apache.portals.jetspeed.version}
...
...
...
...            
...
...
...
...
...
...
...
...
...
...
您可以使用

        <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>

maven antrun插件
测试编译
跑

之后将结果展平。

类似的选项,只是另一个选项,以防答案不起作用。 解压缩到临时目录:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${maven-dependency-plugin.version}</version>
            <executions>
                <execution>
                    <id>unpack-fonts</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifact>
                                <groupId>org.webjars</groupId>
                                <artifactId>font-awesome</artifactId>
                                <version>${font-awesome.version}</version>
                                <type>jar</type>
                                <overWrite>false</overWrite>
                            </artifact>
                        </artifactItems>
                        <!-- Make sure you have the actual folder name that is in the webjar -->
                        <includes>**/webfonts/**/*</includes>
                        <outputDirectory>${project.build.directory}/unpacked</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

org.apache.maven.plugins
maven依赖插件
${maven dependency plugin.version}
解包字体
过程资源
打开
org.webjars
字体真棒
${font.version}
罐子
假的
**/网络字体/**/*
${project.build.directory}/解包
拆包后:

<!-- maven-dependency-plugin does copying too, however; it doesn't seem to be able to flatten the directory structure -->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>copy-files</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/where/you/want /files</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.build.directory}/where/you/unpacked/files</directory>
                                <includes>
                                    <include>**/*</include>
                                </includes>
                                <filtering>false</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

maven资源插件
3.1.0
复制文件
包裹
复制资源
${project.build.directory}/where/you/want/files
${project.build.directory}/where/you/unpacket/files
**/*
假的

20行XML,我本可以用2行bash脚本完成这项工作:(甚至无法使它工作:(我讨厌maven。插件可能无法在maven 3.6中工作,如issues.apache.org/jira/browse/JS2-1366所述。
<!-- maven-dependency-plugin does copying too, however; it doesn't seem to be able to flatten the directory structure -->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>copy-files</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/where/you/want /files</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.build.directory}/where/you/unpacked/files</directory>
                                <includes>
                                    <include>**/*</include>
                                </includes>
                                <filtering>false</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>