3

Hi want some files that are inside a jar copied to the root folder of my java project.

I used this :

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

problem is I get this

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

I want to get this

javaProject
    src
    target
    dll1.dll
    dll2.dll

I don't want the folder path from inside the jar to be reproduced, I just want the files dumped in my project's root.

Any ideas?

Thanks.

Heetola
  • 5,791
  • 7
  • 30
  • 45

3 Answers3

2

You can use the Jetspeed unpack maven plugin: http://pulkitsinghal.blogspot.be/2011/04/jetspeed-finally-unpack-plugin-with.html

See http://portals.apache.org/jetspeed-2/buildguide/jetspeed-unpack-plugin.html for documentation.

The option you want is :

<flat>true</flat>

Full example:

<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>
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
0

You can use

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

to flatten the result afterwards.

user1050755
  • 11,218
  • 4
  • 45
  • 56
0

Similar option, just another option in case the answer was not working. Unpack to a temporary directory:

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

After unpack:

<!-- 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>
Greg
  • 1,007
  • 1
  • 9
  • 9