Sunil Rk
Sunil Rk

Reputation: 1029

renaming a file while creating zip file through Maven-assembly plugin

i am using maven-assembly plugin to create the zip , how can i rename some files while zipping using the same plugin??

Update:

This is the profile in pom

    <profile>
        <id>D1</id>
        <activation>
            <property>
                <name>D1</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>               
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.2.2</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptors>
                                    <descriptor>assembly/online-distribution.D1.xml</descriptor>
                                </descriptors>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

This is Assembly.xml

<?xml version="1.0" encoding="UTF-8" ?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly- 
    plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
    <format>tar.gz</format>
</formats>
<id>online</id>
<includeBaseDirectory>false</includeBaseDirectory>
    <dependencySet>
        <outputDirectory>resources</outputDirectory>
        <unpack>true</unpack>
        <includes>
            <include>${project.groupId}:core-config:jar</include>
        </includes>
        <unpackOptions>
            <includes>
            <include>coresrv/env-config.D1.properties</include>
            </includes>
        </unpackOptions>
    </dependencySet>
    <files>
    <file>
        <source>${project.groupId}/core-config.jar/coresrv/env-config.D1.properties</source>
        <outputDirectory>/</outputDirectory>
        <destName>env-config.properties</destName>
    </file>
</files>
</assembly>

i am getting that jar and unpacking it, then renaming a file and zipping it again. Thanks

Upvotes: 10

Views: 21996

Answers (4)

iceberg
iceberg

Reputation: 1961

You just need to add it in assembly plugin executions like below;

<executions>
 <execution>
  <configuration>
    <finalName>  you can give any name you want  <finalName>
  <configuration>
 </execution>
</executions>

Upvotes: 0

earcam
earcam

Reputation: 6692

Answering an old post for posterity... and next time I ask Google and get sent here.

Renaming used to be a pain in Maven, this plugin does what is says on the tin:

copy-rename-maven-plugin

(available in Maven central)

Easy to use:

        <plugin>
            <groupId>com.coderplus.maven.plugins</groupId>
            <artifactId>copy-rename-maven-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
                <execution>
                    <id>copy-properties-file</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <sourceFile>source.props</sourceFile>
                        <destinationFile>destination.properties</destinationFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Note: the rename goal will move file(s) in target/

Upvotes: 4

Ivan M.
Ivan M.

Reputation: 164

I faced with same problem, I need to use unpack with renaming some files and as solution we can use two executions of maven-assembly-plugin.

During first execution we will use format dir instead of one of archive formats and will prepare files content and as result will have folder with all needed files.

During second execution we will use folder from previous execution as source in fileSets with files and we will have ability to rename any file using files.file.destName, and as format for second execution we can use archive format like zip to create final archive.

Upvotes: 2

khmarbaise
khmarbaise

Reputation: 97487

You can use

 <outputFileNameMapping>...</outputFileNameMapping>

which sets the mapping pattern for all dependencies included in this assembly uses

default value:

${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}.

Upvotes: 14

Related Questions