1

I have the following assembly.xml. I was trying to figure out how when including files I can rename them to something else. Currently, my tar has the war file as project-1.0.0.0.war and I want it to be project.war. How can I accomplish this?

<assembly>
<id>${version}-tar</id>
<formats>
    <format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory>project-${version}</baseDirectory>

<fileSets>
    <fileSet>
        <directory>target</directory>
        <outputDirectory>.</outputDirectory>
        <includes>
            <include>project-${version}.war</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>etc/bin</directory>
        <outputDirectory>.</outputDirectory>
        <includes>
            <include>start</include>
            <include>stop</include>
        </includes>
    </fileSet>
</fileSets>

2 Answers 2

1

If you want to control the destination name of the file in the assembly, you shouldn't use a <fileSet>, but a <file>. The reason is that the first groups several files together, and as such, doesn't provide a way to control the name of each file in the group. Since a <file> targets only a single file, you can control the destination name with the <destName> element:

Sets the destination filename in the outputDirectory. Default is the same name as the source's file.

You should have instead:

<files>
  <file>
    <source>target/project-${version}.war</directory>
    <destName>project.war</destName>
  </file>
</files>
<!-- the other "fileSets" for etc/bin, unchanged -->

instead of the <fileSet>. This will make sure that the file specified in the <source> element is renamed to <destName> in the resulting assembly.

2
  • thanks! followup q i guess, if i want to include all files in a directory, what's the proper syntax? Dec 9, 2016 at 16:48
  • 2
    @iCodeBadly Just don't specify an <include> element to the <fileSet>; by default it includes everything under the specified directory. If you specifically want files, but not folder, <include>*</include> should work
    – Tunaki
    Dec 9, 2016 at 16:50
1

You are looking to add:

<build>
    ...
    <finalName>${artifactId}</finalName>
    ...
</build>

Documentation

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

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