maven create zip with jar and some more files - maven

I do not understand maven. Better use ant, but... I've managed to create jar (with, or without dependencies), I've managed to copy bat runner script close to jar but now i want to create zip with this jar and this bat. So i use assembly plugin and get BUUUM!!!! CADAAAM! In my configuration it happens so, that it executes parallel to jar packaging. I wrote assembly 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>jg</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/123</outputDirectory>
<excludes>
<exclude>assembly/**</exclude>
<exclude>runners/**</exclude>
</excludes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
Then, I bound maven-assembly-plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>false</inherited>
<configuration>
<archive>
<manifest>
<mainClass>by.dev.madhead.lzwj.Main</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/assembly/assembly.xml</descriptor>
<!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Now I get this in ./target:
runner.bat
jar_without_dependencies.jar (it is from maven-jar-plugin, right?)
jar_without_dependencies.jar
And the third angers me. It contains:
And the 123 directory contains:
As you see, I get jar with unpacked dependencies, EXCLUDED DIRS!!!!, and with dir 123, which is actually what I want (Oh! assembly plugin did that!!!).
I want to get jar with dependencies and correct manifest with classpath. As an option i want jar with unpacked dependencies (I know about <unpack>false</unpack> in assembly, but cannot get it work). I want to change /123 to / and get NORMAL JAR WITHOUT EXCLUDED FILES!!! I want two separate tasks to build jar and zip (is it done with profiles in maven??) As in ant, i would wrote something like this:
<target name="jar_with_deps" depends-on="compile">
<jar>
here i copy classes (excluding some dirs with runner script), and build manifest
</jar>
<copy>
copy bat file from src/main/resources/runner/runner.bat
</copy>
</target>
<target name="zip" depends-on="jar_with_deps">
<zip>
Get jar from previous target, get runner.bat. Put them in zip
</zip>
</target>
Excuse me, if I am too expressive, but I am really angry with this implicit behavior. I am really stuck with this.

Just in case it helps anyone else, I found that this was pretty easy to do, at least for my basic needs. I was already using the Maven Shade plugin to build a jar with all dependencies included:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration></configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
So when I ran mvn package, it would produce target/MyApp-version.jar, whereas I wanted a MyApp-version.zip containing MyApp-version.jar along with some other files (a README, etc.). So, I add the Assembly plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
The above block refers to assembly.xml, which configures the way the plugin works:
<?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>release</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>target</directory>
<includes>
<include>MyApp-${app.version}.jar</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<source>CHANGES.md</source>
<fileMode>0644</fileMode>
</file>
<file>
<source>LICENSE</source>
<fileMode>0644</fileMode>
</file>
<file>
<source>README</source>
<fileMode>0644</fileMode>
</file>
</files>
</assembly>
(${app.version} is defined in the pom.xml <properties> element.)
That's it, now mvn package produces both the jar and the zip.

You have to options to achieve your goal:
option: Create two assembly descriptors, one for jar w/ deps and one for zip. Zip takes the the newly created jar.
option: Create two more modules in your project: first modules shades all deps into one jar (or attach a shaded jar along with your main jar, save another module), have the second module depend on it and suck in that jar in your assembly. Your done.
Depending on the size and structure of your project, I would go for the safe way: option 2. This one is guaranteed to have the correct build and dep order. Option 1 violates the maven way somewhat.

I've made two profiles in pom.xml:
<profiles>
<profile>
<id>jar-with-dependencies</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<archive>
<manifest>
<mainClass>by.dev.madhead.lzwj.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>distro</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/distro.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Now i am able to create simple jar (mvn clean package), jar with dependencies (mvn clean package -Pjar-with-dependencies). I also can call mvn package -Pdistro to create zip. But i need to call maven with -Pjar-with-dependencies before it manually. Except this, everything is ok.

Related

maven-assembly-plugin loops over each module without being told to do so

I am just trying to copy some files into some directories, and using this plugin since I am told that it is convenient. However, whenever I try to do mvn install, the plugin somehow tries to loop over every module in my pom.xml (I never asked it to do this kind of thing) and tries to do some operation, then gives the error of :
Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-install-assembly) on project untoldProject Failed to create assembly: Error creating assembly archive install: You must set at least one file.
I want this plugin to operate on only certain modules (and folders which are not modules) which I already specify in the path, in the assembly file of mine. So I don't know why is the plugin tries to do this operation for every module.
Here is my pom.xml where I use the plugin:
<!-- This plugin is used to copy the necessary files to project.release/install folder -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-install-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>true</inherited>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
Here is my asssembly.xml where I specify what I want to copy:
<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>install</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>project.release/template</directory>
<outputDirectory>project.release/install</outputDirectory>
<lineEnding>unix</lineEnding>
<filtered>true</filtered>
<includes>
<include>run.all.sh</include>
<include>kill.all.sh</include>
<include>packlogs.sh</include>
</includes>
<excludes>
<exclude>config.properties</exclude>
<exclude>run.all.ant</exclude>
<exclude>run.ant</exclude>
<exclude>packlogs.sh</exclude>
<exclude>install.sh</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
Given this, why does the plugin try to do this operation for every module? I just want it to happen for one module, called project.release, and that's it. I put both of my pom.xml and assembly.xml to the parent directory, for your information.
Update: For those who would like to see my project hiearchy, here is my master pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>runtime_project</groupId>
<artifactId>runtime_project.master</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<modules>
<module>project.messages</module>
<module>project.base</module>
<module>project.logging</module>
<module>project.mission.launch</module>
<module>project.mission.detach</module>
<module>project.settingsStore</module>
</modules>
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- This plugin is used to delete the contents of the project.release/install folder-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>project.release/install</directory>
<followSymlinks>false</followSymlinks>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- This plugin is used to copy the necessary files to project.release/install folder -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-install-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>true</inherited>
<configuration>
<descriptors>
<descriptor>deploy.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Given this, why does the plugin try to do this operation for every
module?
Because this is the nature of multi module project.
I just want it to happen for one module, called project.release, and
that's it. I put both of my pom.xml and assembly.xml to the parent
directory, for your information.
I give some hints, not a complete solution.
create an additional module called project.release. Add it to the <modules> element in the root POM. The order doesn`t matter
move the plugin-entry for the maven-assembly-plugin from the root POM to the POM of project.release
In the POM of project.release, add dependencies to other modules as necessary.
In the folder of project.release, place the assembly descriptor in src/main/assembly . The directory entries within your descriptor should be relative to the module root of project.release

Maven assembly: generate a resource zip file and include it into the main assembly zip file

How can I proceed to include a generated zip file into a main zip file with the Maven Assembly plugin?
For example, I have the following folder structure:
./folderA/
./file1
and I want to generate a zip file where the content is like this:
folderA.zip
file1
Here my simplified config':
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project >
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptor>${basedir}/assembly-zipFolderA.xml</descriptor>
<finalName>folderA.zip</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptor>${basedir}/assembly.xml</descriptor>
<finalName>${module-zipFinalName}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>
assembly-zipFolderA.xml
<assembly>
<id>folderA-zip</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>folderA</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
assembly.xml
<assembly>
<id>main</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>file1</source>
</file>
<file>
<source>folderA.zip</source>
</file>
</files>
</assembly>
===> with this config, Maven complains that it can't find folderA.zip...
Don't declare the plugin twice; instead, you need to declare two executions of the maven-assembly-plugin.
The first execution will create the first assembly and then, the second execution will use this assembly to create the final one. Both of those executions will be bound to the package phase, and Maven will invoke the plugin's execution in the order of declaration in the POM.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-folderA</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/assembly-zipFolderA.xml</descriptor>
</descriptors>
<finalName>folderA</finalName> <!-- name without extension -->
<attach>false</attach>
</configuration>
</execution>
<execution>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/assembly.xml</descriptor>
</descriptors>
<finalName>${module-zipFinalName}</finalName>
</configuration>
</execution>
</executions>
</plugin>
A couple of notes:
The <finalName> should not contain the extension, so a finalName of folderA will produce the archive folderA.zip after the ZIP assembly is made.
The first assembly will be created inside the build directory, which is target by default. As such, the second one needs to reference it there with:
<file>
<source>${project.build.directory}/folderA.zip</source>
</file>
in its assembly descriptor.
Since the first assembly is not the final one, you probably don't want it attached, i.e. as an additional artifact produced by your project. You can disable this by setting attach to false. This will make sure only the last final one is considered when deploying or releasing.
descriptor is a deprecated parameter, you should use descriptors instead.
With such a configuration, running mvn clean package will produce the correct archive inside the build folder.

Generate several war for spring boot application

It seems that spring boot will repackage the package generated by maven package phase, and then repacke the war to make it executable.
Now I want to genrate multiple wars for different environments by a single maven command, I tried to use maven-assembly-plugin:
1 unzip the war generated by `spring-boot-maven` plugin to a directory
2 Assembly with the files in the directory, and add some other filtered resources
3 create the war
Check this post:generate multiple artifacts in maven
While it works, and I got multiple wars, but none of them can be executeable by java -jar xx.war. It seems that the classes are corrupted.
So I wonder if there is an alternative solution?
update my pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/as-common</source>
<source>src/main/as-server</source>
<source>src/main/as-app</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- unzip the contents of the war(executeable) generated by spring-boot to a certain directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>extract_spring_war</id>
<phase>package</phase>
<configuration>
<target>
<echo message="extract war generated by spring-boot-maven-plugin"/>
<delete dir="${basedir}/target/${project.build.finalName}-spring" includeemptydirs="true"/>
<unzip src="${basedir}/target/${project.build.finalName}.war" dest="${basedir}/target/${project.build.finalName}-spring/"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<items>
<item>test</item>
<item>dep1</item>
<item>dep2</item>
</items>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
</plugin>
<goal>single</goal>
<configuration>
<archive>
<manifest>
<mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
assmbly.xml:
<assembly>
<id>${item}</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- file from the unpacked contents -->
<fileSet>
<directory>target/${project.build.finalName}-spring</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<filtered>true</filtered>
</fileSet>
<!-- add environment awared resources -->
<fileSet>
<outputDirectory>/WEB-INF/classes</outputDirectory>
<directory>${basedir}/src/main/custom/</directory>
<includes>
<include>${item}.properties</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Update:
At first I got the error:
No main class detected
Then I add the following for maven-assembly-plugin,
<archive>
<manifest>
<mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
</manifest>
</archive>
After that I repackage the wars, and I got error when I ran:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 4022320623 in class file org/springframework/boot/loader/WarLauncher
The class files are being corrupted when you're repackaging the war file. I suspect that's because you're filtering all of the files:
<fileSet>
<directory>target/${project.build.finalName}-spring</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<filtered>true</filtered>
</fileSet>
You don't want to filter binary files as they may happen to contain data that looks like a ${} placeholder. You should update the assembly to avoid applying the filtering to class files. The simplest way to do that would be to disable filtering entirely:
<fileSet>
<directory>target/${project.build.finalName}-spring</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<filtered>false</filtered>
</fileSet>
If you need filtering for text files, you should use two fileSets. One that includes the binary files and disables filtering, and one that includes the text files and enables filtering.

Package Dll in Jar using Maven- single goal

I have added a DLL in my maven project as dependency like this :
<dependency>
<groupId>com.test.dll</groupId>
<artifactId>myDll</artifactId>
<version>0.1</version>
<type>dll</type>
</dependency>
When I try to execute maven:install
It is giving me this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-
beta-5:single (jar-with-dependencies) on project testApp: Failed to create
assembly: Error adding file-set for 'com.test.dll:myDll:dll:0.1' to archive: Error
adding archived file-set. PlexusIoResourceCollection not found for: C:\Users\USER\.m2
\repository\com\test\dll\myDll\0.1\myDll-0.1.dll: No such archiver: 'dll'
What Am I doing wrong here??
Update
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>src/main/keystore/mykey.keystore</keystore>
<alias>aliasname</alias>
<storepass>passw0rd</storepass>
<verify>true</verify>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
The problem here is the jar-with-dependencies descriptor. The descriptor unpacks all dependencies into a directory and packages this directory into a new JAR file. However, it cannot unpack a DLL file (that's the "No such archiver" error message). To get this working, you need to define your own assembly descriptor:
<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>assembly-with-dll</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!-- package the regular dependencies -->
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<!-- exclude the DLL -->
<excludes>
<exclude>com.example:my-dll</exclude>
</excludes>
</dependencySet>
<!-- package the DLLs -->
<dependencySet>
<outputDirectory>/</outputDirectory>
<includes>
<include>com.example:my-dll</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
Provided, that the descriptor above resides in src/main/assembly, the configuration of the maven-assembly-plugin looks as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
There is a piece of information here : Maven Dll Dependency Problem.
To solve this issue, exlude dll from your assembly :
<excludes>
<exclude>*:dll*</exclude>
</excludes>
Last time I had to create a executable jar with dependencies, I put them out of the jar, in a lib directory.
DLL must be :
either in application classpath (like server/lib for a server)
or in the OS classpath (C:\Windows\system32 for instance)
After reading your pom and dependecy file set, I may be able to be more accurate :)
To add to Stefan's answer, I don't think you want to do a jar-with-dependencies packaging for this project of yours. You should look at using one of the bin packaging (like .zip or tar.gz)

How to define the order of executions using maven-assembly-plugin

I am working on the migration of a project from Ant to Maven. The final distribution I need to deliver is a zip containing an executable jar with all its depencencies. Here is part of my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<configuration>
<finalName>ProjectDistribution</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>fullQualifiedNameToMainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/dep.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>dist</id>
<phase>assembly</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
And here is the assembly file:
<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<!-- 1st approach-->
<!--files>
<file>
<source>
/target/ProjectDistribution.jar
</source>
<outputDirectory>/</outputDirectory>
</file>
</files-->
<fileSets>
<!-- 2nd approach-->
<!--fileSet>
<directory>/target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet-->
<fileSet>
<directory>/HelpFiles</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.*</include>
</includes>
</fileSet>
</fileSets>
I run 1.- mvn compile, 2.- mvn package, and 3.- mvn assembly:single
The problem I am dealing with is that
It does generate the jar with all the dependencies and it does generate the zip but it does not includ the jar in the zip. I pretty much need to figure out a way of making the assembly first generate the jar and wait until it is created (because its size is 5 MB) and then create the zip. Right now the 1st and 2nd approaches -from the assembly file- are commented out, however, I have used both and none of them seem to work.
Any help will be greatly appreciated!
Eric
To get this working you need to split the <configuration> and put it into the two plugin executions:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>verify</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>ProjectDistribution</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>fullQualifiedNameToMainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>dist</id>
<phase>verify</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/dep.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The first execution will create the jar file. The second execution will take that JAR file and
put it into the ZIP file together with the other files. With this configuration, you can just execute mvn verify or mvn install to create the assembly.
There are two other things to consider:
You should use the verify phase to build your assembly because the jar-with-dependencies descriptor includes the project artifact itself. During the package phase the project artifact will not be ready for packaging
The jar-with-dependencies descriptor has very limited capabilities to create a JAR file with all dependencies. You should use the maven-shade-plugin instead.
You are mixing the pre-defined jar-with-dependencies with a custom zip descriptor. You would normally want one of them - not both.
It looks like you want a zip which contains your project artifact along with its dependencies. For this you would not need to create a jar-with-dependencies. If, however, you do want a single executable jar with all the dependencies in it, then it is not clear why you need to zip it again.

Resources