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

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>

Related

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.

How can a jar with specific deps be created, after using maven-dependency-plugin to select the wanted deps?

My goal is to create a jar with specific dependencies from my dependency list in the pom. I'm using maven-dependency-plugin like so:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<includeScope>runtime</includeScope>
<excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>
<outputDirectory>${project.build.directory}/uber-deps/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.some.blaClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
and an assembly.xml file holding:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>plugin</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<includes>
<include>
${project.build.directory}/uber-deps/
</include>
</includes>
<excludes>
<exclude>*:sources</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
After mvn clean install all relevant dependencies appear in target/uber-deps as I would expect. My problem is with the next plugin under <plugins> - maven-assembly-plugin. Seems to me as if it doesn't take uber-deps in.
I know this only by trying to unpack the jar using jar xf to see if the deps in uber-deps were packed in the jar created after mvn clean install.
What should be changed?
1)
The jar you are building as part of the assembly-plugin will be called (by default) ./target/<artifactId>-plugin.jar
Note that the plugin part is what you've put under id in your assembly xml file.
2)
Since you already unpack the dependencies to a folder, you should use fileSets rather then dependencySets:
<fileSets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<includes>
<include>
${project.build.directory}/uber-deps/
</include>
</includes>
</fileSet>
</fileSets>
</fileSets>
3)
BTW if you want the outputs of your own project in that jar you should add another fileSet:
<fileSet>
<outputDirectory>/</outputDirectory>
<includes>
<include>
${project.build.outputDirectory}
</include>
</includes>
</fileSet>
4) Also just noted that your assembly plugin definition is not stating the location of your assembly xml file and that you try to define mainClass using shade-plugin configuration. This is how it should look in assembly plugin (assuming that your assembly file is located under src/assembly/plugin.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>src/assembly/plugin.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.some.blaClass</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>

Maven build zip file from generated resources

How I can build zip file from generated resources?
Trying to generate a zip file for all generated files under target. Not sure where the problem is:
assembly:
<id>resources-bundle</id>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>${project.basedir}/</outputDirectory>
<directory>${project.basedir}/</directory>
<includes>
<include>**/target/dependency/**.properties</include>
</includes>
</fileSet>
</fileSets>
pom entry:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<goals>
<goal>single</goal>
</goals>
<phase>validate</phase>
<id>archive</id>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<formats>
<format>zip</format>
</formats>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
error I'm facing:
Failed to create assembly: Error creating assembly archive test-libs: You must set at least one file.
Any help much appreciated!
Thanks
Resolved!
assembly.xml::
<fileSet>
<outputDirectory>resources/</outputDirectory>
<directory>${project.basedir}/target/dependency/</directory>
<includes>
<include>**/**.properties</include>
</includes>
</fileSet>
pom.xml:
<execution>
<id>pack-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<formats>
<format>zip</format>
</formats>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
Thanks

Assembly ID is getting appended when zip file is created by maven

xml and pom.xml which creates jar file and then zip file with some artifacts including jar file. But when i run maven install zip file is getting created as GenerateMissingUsersReport-bin.zip instead I want it to create as GenerateMissingUsersReport.zip. I have set as false. But no difference.
Any pointers?
Here is dep.xml
<id>bin</id>
<baseDirectory>../</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<includes>
<include>plugin.xml</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
Here is pom.xml
<finalName>GenerateMissingUsersReport</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>GenerateMissingUsersReport</finalName>
<appendAssemblyID>false</appendAssemblyID>
<descriptor>src/assembly/dep.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>plugin.xml</exclude>
</excludes></configuration>
</plugin>
Add the following line under configurations element of the pom
<appendAssemblyId>false</appendAssemblyId>
Also make sure you use the latest version of the assembly plugin
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>

Annotated class not found in jar file generated by maven-assembly-plugin

I'm using the maven-assembly-plugin to generate a jar file with a single class inside. When I try to deploy my jar to JBoss server I receive an error: No annotated classes found in the jar:. I've decompiled the class file from the jar and it is annotated. My only guess is for some reason the maven-assembly-plugin is causing an issue. If I generate the jar from a command line and inserting the same .class file the deployment will work.
snippet of the plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<inherited>false</inherited>
<executions>
<execution>
<id>make-RC04InquirySvc-v1.jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<finalName>RC04InquirySvc-v1</finalName>
<descriptors>
<descriptor>assembly-RC04InquirySvc-v1.xml</descriptor>
</descriptors>
<archive>
<manifestEntries>
<Implementation-Vendor>EDS</Implementation-Vendor>
<Implementation-Title>Agile Card Framework</Implementation-Title>
<Implementation-Version>6.0</Implementation-Version>
<Built-Date>${maven.build.timestamp}</Built-Date>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
And the assembly file:
<assembly>
<id>acf-bundle</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes/com/eds/agilecard/wsdl/rc04Inquirysvc_v1</directory>
<outputDirectory>/com/eds/agilecard/wsdl/rc04Inquirysvc_v1</outputDirectory>
<includes>
<include>**/ServiceEndpointImpl.class</include>
</includes>
</fileSet>
</fileSets>
</assembly>

Resources