6

I have a very specific requirement of our build infrastructure to copy some contents of another JAR dependency to a specific sub-folder of my web-application. We're using maven-assembly-plugin, and a natural way to do this is to use <dependencySet> along with <unpackOptions>.

The code sample (in assembly descriptor) I have looks as following:

    <dependencySet>
        <unpack>true</unpack>
        <scope>runtime</scope>
        <useProjectArtifact>false</useProjectArtifact>
        <includes>
            <include>my.group:artifact:jar</include>
        </includes>
        <unpackOptions>
            <includes>
                <include>subfolder/config.xml</include>
            </includes>
        </unpackOptions>
        <outputDirectory>WEB-INF/otherfolder</outputDirectory>
    </dependencySet>

The problem is that I can't figure out how to specify that I only want to copy just a single file artifact.jar/subfolder/config.xml to a target WEB-INF/otherfolder. The actual result is WEB-INF/otherfolder/subfolder/config.xml. As you can see, /subfolder gets appended to a final path. Is there any way to change the <include> expression so that /subfolder doesn't get appended?

Thanks in advance!

6
  • Have you tried to remove the otherfolder from the outputDirectory ?
    – khmarbaise
    Jun 22, 2012 at 12:58
  • @khmarbaise In that case I will get WEB-INF/subfolder/config.xml. But the expected result is WEB-INF/otherfolder/config.xml
    – Art Licis
    Jun 22, 2012 at 12:59
  • try **/config.xml and see what happens..
    – om39a
    Jun 22, 2012 at 13:13
  • @om39a The full path is appended, just like in the original descriptor...
    – Art Licis
    Jun 22, 2012 at 13:16
  • @ArtursLicis Buddy.. Check this link I think this is wat you need.
    – om39a
    Jun 23, 2012 at 2:18

4 Answers 4

2

Have you ever thought about the maven-dependency-plugin which has a good support for unpacking archives.

1
  • I have thought, and I will rethink again as I will clean up the build scripts. But, to be honest, this is not an answer to a question.
    – Art Licis
    Jun 22, 2012 at 18:56
2

Browsing through source reveals that this is not possible via maven-assembly plug-in. It gets all includes that are specified in assembly descriptor, and then passes this information to Plexus archiver which is used through multiple stages. Include patterns are passed to Plexus archiver as well, and then it obviously performs 'unpack' conserving directory structure.

0
1

As @khmarbaise indicates, the solution lies in combining dependency-plugin with assembly-plugin:

  • On package phase start by unpacking the dependencies you need to some target directory
  • On package (later in pom) use assembly to extract specific files from that directory into your artifact
0

Try this out with the <file/> tag and destName:

https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.