How to provide a custom name to extracted folder from a zip, generated using maven-assembly-plugin - maven

I'm using the maven assembly plugin to package a few directories into a zip file.
The following is the zip.xml.
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<baseDirectory>${project.build.directory}</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/bin</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}/config</directory>
<outputDirectory>config</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>lib</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Following is the plugin configuration in pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
<finalName>bootstrap</finalName>
</configuration>
</execution>
</executions>
</plugin>
When I run the assemply, a zip file is created with the name of my maven module, which is as expected. But when I extract this zip file, a folder named 'target' is created which is not very readable. How do i customize the name of this 'target' folder?

Related

How to create password-protected zip in maven

currently I am using maven-assembly-plugin to create a zip file via "mvn clean package". The whole process works fine, the zip contains everything I need but a new requirement asks to create this zip file password-protected. I googled but not found any useful; is there anyone who needed to perform this task ?
Current plugin is defined in this way:
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</build>
and zip.xml is defined in this way:
<?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"
>
<id>zip</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>directory1/</outputDirectory>
<directory>directory1</directory>
</fileSet>
<fileSet>
<outputDirectory>/</outputDirectory>
<includes>
<include>config.properties</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>target/data-jar-with-dependencies.jar</source>
<destName>data-jar-with-dependencies.jar</destName>
</file>
</files>
</assembly>
You must use an external program to unzip and zip the archive again. For example 7z:
7z e Unprotected.zip
7z a Protected.zip -pPASSWORD UNPROTECTEDFILENAME
If you want to integrate it in the build lifecycle then you need the maven exec-plugin to execute those two commands after the package phase.

save zip with a different file name using maven-assembly-plugin

I want to be able to zip files in folder '${project.basedir}/src/main/resources/docker' to folder target/docker-files/docker-files.zip but currently they are getting saved in 'target/project-artifactId-1.0-SNAPSHOT.zip'
I have written the following zip.xml file
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>docker_files</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/docker</directory>
<filtered>true</filtered>
<outputDirectory>/docker-files-zip</outputDirectory>
</fileSet>
</fileSets>
</assembly>
My pom.xml has the following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<fileName>docker-files</fileName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Any leads would be really helpful.

Maven assembly plugin - "install" folder

I have configured maven assembly plugin which generates "tar.gz" file.
However, when I untar, it somehow includes "install" folder at the beginning:
/install/lib
/install/scripts
My requirement is that, upon untar, it should have folders like below, no install directory:
/lib
/scripts
My pom.xml plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>install</finalName>
<descriptors>
<descriptor>assembly/app-assembly.xml</descriptor>
</descriptors>
<tarLongFileMode>posix</tarLongFileMode>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
app-assembly.xml:
<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">
<id>myapp</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<excludes>
<exclude>src/**</exclude>
<exclude>readme.md</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Appreciate any help or guidance on this. Thanks for reading.
https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
includeBaseDirectory: Includes a base directory in the final archive. For example, if you are creating an assembly named "your-app", setting includeBaseDirectory to true will create an archive that includes this base directory. If this option is set to false the archive created will unzip its content to the current directory.
Default value is: true.

how in maven multiple folders to the multiple zip archives with the same names

I want to collect the project module using, Maven
I have a directory structure. Folders can be added dirN:
project-module
|
|-dir1
|-dir2
|-dir3
|-...
|-dirN
|-bin.xml
|-pom.xml
I tried the maven-assembly-plugin
pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>bin.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>sql dir</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
bin.xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>../mspost-db</directory>
<excludes>
<exclude>*.*</exclude>
</excludes>
<useDefaultExcludes>false</useDefaultExcludes>
<!--<outputDirectory>/</outputDirectory>-->
</fileSet>
</fileSets>
</assembly>
DESIRED OUTCOME
Each directory to be packaged into a single zip archive folder with the same name, that is.
project-module
|
|-targer
|-dir1.zip
|-dir2.zip
|-dir3.zip
|-...
|-dirN.zip
help me please.
The iterator-maven-plugin could be used to work with a single assembly descriptor:
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<items>
<item>dir1</item>
<item>dir2</item>
<item>dir3</item>
</items>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<goal>single</goal>
<configuration>
<descriptors>
<descriptor>${project.basedir}/bin.xml</descriptor>
</descriptors>
<finalName>${item}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
Then reference ${item} in the bin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>${item}</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/${item}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
This results in target/dir1.zip etc.
Instead of listing the <items> explicitly, it can also iterate over a <folder>, though I don't see a way that could be restricted to such as dir*.
(Edit start)
E.g. to iterate the (immediate) subdirectories of parentDir:
<configuration>
<folder>${project.basedir}/parentDir</folder>
<pluginExecutors>
... as above ...
The assembly descriptor (bin.xml) can then reference something like <directory>${project.basedir}/parentDir/${item}</directory>, much as before.
The lack of a filter would still be an issue if iterating over <folder>${project.basedir}</folder> though - this would zip up the target directory too.

do not create meta-inf/maven in jar package when using maven assembly plugin

I have one project that using maven assembly plugin for merging two jar,without using maven assembly ,create jar package have meta-inf/maven that contain pom.properties and pom.xml . but after merge by Assembly this folder not exists.
i search it and found that this can make that OK but dose not work .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>src/assembly/frm-assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<archive>
**<addMavenDescriptor>true</addMavenDescriptor>**
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
and descriptor is this
<assembly>
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/webapp</directory>
<outputDirectory>/META-INF/resources</outputDirectory>
</fileSet>
</fileSets>
</assembly>

Resources