I have a zip.xml in a folder named assembly:
<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>archive</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
</fileSet>
<fileSet>
<directory>src/main/resources/</directory>
<includes>
<include>plugin-descriptor.properties</include>
</includes>
</fileSet>
</fileSets>
</assembly>
After I build the project using mvn clean -U -DskipTests package assembly:assembly, I notice that only the jar file was copied and zipped to the archive.
How can I make the properties file to archived in the zip file? The wanted zip should have the jar and properties file in root
You should define a <files> element instead of a <fileSets> since you want to copy specific individual files and not a directory. In this case, you want to copy:
${project.build.directory}/${project.build.finalName}.${project.packaging} into the root of the ZIPsrc/main/resources/plugin-descriptor.properties into the root of the ZIPYour current configuration is wrong because you are declaring to ZIP all entries under ${project.build.directory}, which is not what you want, since you're only interested in the final JAR. Also, using / as base directory is a bit weird; it would be better to say that we don't want a base directory with <includeBaseDirectory>false</includeBaseDirectory>
A sample configuration would be:
<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>archive</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>${basedir}/src/main/resources/plugin-descriptor.properties</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With