I followed the answer for how to create a ZIP archive in Maven here: https://stackoverflow.com/a/2514677/1395165
and have a couple of follow-up questions:
ZIP contents to exclude directory:
As in the example I have:
<fileSet>
<directory>${project.basedir}/src/export</directory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
In the ZIP I get
src
export
Dir1
Dir2
but I only want to have
Dir1
Dir2
in the ZIP. Is that possible?
Output file name
The output file name is created with a .zip extension. Is it possible in Maven to override the extension to something else (say .abc)?
The outputDirectory option can be used to change the directory within the assembly that the files are output to - this should do what you need:
<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>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}/ScriptedBuild/rConnect/extract/</directory>
<useDefaultExcludes>true</useDefaultExcludes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
set includeBaseDirectory to false - see http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
Use
<assembly ...
<baseDirectory>/</baseDirectory>
And
<fileSet>
<outputDirectory>/</outputDirectory>
That will put all files in the root of the zip file.
BaseDirectory sets the directory inside the zip to use for all files, like it prepends it to all paths. That way when you upzip it without making a directory first, it doesn't pollute your current working directory.
OutputDirectory sets the directory inside the zip file. BaseDirectory is still 'prepended' to this. So BaseDirectory = /project-1.2.3 and OutputDirectory /src will create project-1.2.3/src/ inside the zip.
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
baseDirectory String Sets the base directory of the resulting assembly archive. If this is not set and includeBaseDirectory == true, ${project.build.finalName} will be used instead. (Since 2.2-beta-1)
outputDirectory String Sets the output directory relative to the root of the root directory of the assembly. For example, "log" will put the specified files in the log directory.
Related
During assemby, I want include all files from a release directory into the root of my assembly.
If I do the following:
<fileSet>
<directory>${basedir}/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>src/main/resources/release/**</include>
</includes>
</fileSet>
Then all of the files get added to a folder named src/main/resources/release/ inside my release.
Is there a way to not include the folder path when including the fields?
I'm using the 2.3 version of the assembly plugin. If there is not a way to do this with the assembly plugin is there a way to do this with other plugins? (preferably without resorting to the ant plugin).
You have to do the configuration a little bit different like this:
<fileSet>
<directory>src/main/resources/release/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>
I am trying to add specific directories from Maven modules into my build. I believe that fileSets are the way to go back this.
I would appreciate a clear and concise way of using fileSets to obtain necessary directories from Maven modules that just simply contain a directory with some necessary resources.
If you want to include entire modules, use moduleSets, but if you want to pick and choose which files to add you can use fileSets in an assembly config file from the top level project like this:
<fileSets>
<fileSet>
<directory>${basedir}/myModule/src/main/resources</directory>
<includes>
<include>*.txt</include>
</includes>
</fileSet>
</fileSets>
Is it possible to perform a patch release in maven? I would like to create a jar containing only one class which I have changed since the release.
There is no generic way to do that, as far as I know.
However, the simplest way to do that is to create a simple assembly that will create a JAR or a ZIP containing your classes. The assembly.xml will only need to include the specified class file:
<assembly>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>target/classes/foo/bar/FooBar.class</source>
<outputDirectory>foo/bar</outputDirectory>
</file>
</files>
</assembly>
(note that I didn't test this script)
Then, after compiling (mvn clean install) your project, you will just need to run the command mvn assembly:assembly to create your ZIP file.
I am using Assembly plugin for maven to create an installation package.
For my packaging requirement, I need to split artifacts generated during the build and all dependencies into separate folders.
My current Assembly manifest is as follows:
<moduleSets>
<moduleSet>
<includes>
<include>test:test</include>
</includes>
<binaries>
<includeDependencies>false</includeDependencies>
<outputDirectory>lib/custom/${artifactId}</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
<moduleSet>
<includes>
<include>test:test</include>
</includes>
<binaries>
<includeDependencies>true</includeDependencies>
<excludes>
<exclude>test:test</exclude>
</excludes>
<outputDirectory>lib/thirdParty/</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
First moduleset correctly generates only currently built assembly.
However, thirdParty includes the currently built assembly as well. How would I go about excluding the files already included in the first set?
Thanks
What about using dependency:copy-dependencies? I use that to copy all deps to target/lib .
One kludgy way to do it is with the maven-antrun-plugin and an ant task. Iterate the contents of lib/custom/${artifactId} and remove any files from lib/thirdParty.
You might want to look at appassembler-maven-plugin. It lets you dump all your runtime dependency jars in a directory. You might be able to hack that up to put your main jar in one folder and then dump the dependencies into another.
I am creating an assembly with packaging=war.
I need to include few of the jars, which have been declared as project dependencies in pom.xml in my war (web-inf/lib)
How can I do this?
Edited on 15/10-
My project creates few assemblies, one of which is supposed to give packaging of type-war.
Some jar files, which are dependencies for the project(and have been declared in pom.xml)need be included in war under WEB-INF.
How can I include them or how can i point out their paths to my local nexus repository path?
Can you be more precise? By default, when you run the mvn clean install command on a war project, Maven 2 will include all dependencies in WEB-INF/lib directories, excluding the ones with the scope test and provided.
If you create your war file using an assembly, then you have an assembly.xml file, which defines the content of your final war file. In this file, you can specify the list of dependencies you want to include:
<assembly>
...
<dependencySets>
<dependencySet>
<includes>
<include>log4j:log4j</include>
<include>commons-lang:commons-lang</include>
...
</includes>
<unpack>false</unpack>
<outputDirectory>WEB-INF/lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
(in this example, I asked to add log4j and commons-lang dependencies).
For each dependency, you need to specify the groupId and the artifactId. The version is automatically detected regarding the list of dependencies you have set in your pom.xml file.