I want to build a standalone archive that includes an OSGi container for my project's bundles to run in. The goal is to have an archive that can be downloaded, unpacked, and started right away.
I'm using the Maven assembly plugin to create the archive. With the assembly descriptor below and a single dependency on Apache Karaf, I get the following structure in my archive:
+-apache-karaf-2.2.1 | +-bin +-demos ... etc ..
I want to strip the base directory of the unpacked dependency, have my own base directory at the top and exclude some of the folders (e. g. demos
) and then add my own bundles and config files. It looks like I can't do all of that with the assembly plugin, is there another plugin I can use?
Here's my assembly descriptor:
<assembly>
<id>dist-full</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>false</useTransitiveDependencies>
</dependencySet>
</dependencySets>
</assembly>
Note that includeBaseDirectory
is only set to false because I want to at least have the number of levels right, then I just have to rename the thing after unpacking. It would be better to keep the base dir and get rid of the dependency's basedir instead.
Use the maven-dependency-plugin
to unpack the dependencies and then use fileSets
in the assembly descriptor. Like so:
pom.xml:
<project>
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>apache-karaf</artifactId>
<version>2.2.1</version>
<type>tar.gz</type>
</dependency>
</dependencies>
<!-- ... -->
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>prepare-runtime</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distribution-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- ... -->
</project>
assembly.xml:
<assembly>
<id>dist-full</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>${groupId}.${artifactId}-${version}</baseDirectory>
<fileSets>
<fileSet>
<directory>target/dependency/apache-karaf-2.2.1</directory>
<outputDirectory />
<includes>
<include>bin/**</include>
<include>lib/**</include>
<include>etc/**</include>
<include>deploy/**</include>
<include>system/**</include>
</includes>
</fileSet>
</fileSets>
</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