- Create a custom Apache Karaf distribution using karaf-maven-plugin
- Create a custom logo using maven-bundle-plugin
- Configure karaf-maven-plugin
- Build a OSGi bundle using maven-bundle-plugin
- Use maven-dependency-plugin for post-processing
Karaf 2: Coming soon
Karaf 3: https://github.com/juttayaya/karaf/tree/master/karaf3/custom-karaf
Karaf 4: Coming soon
Step 1: Import the Karaf 3 dependencies
Add the following entry in the dependencyManagement section of the pom.xml
<dependencyManagement>
<!-- Import Karaf POM to use the correct
version of the Karaf dependencies -->
<dependencies>
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>karaf</artifactId>
<version>${karaf.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Doing this will automatically configure the custom Karaf Maven build to use the correct version of dependencies libraries.
See https://github.com/juttayaya/karaf/blob/master/karaf3/custom-karaf/pom.xml for full example.
Step 2: Configure the karaf-maven-plugin
Add the following entry to the pom.xml to configure karaf-maven-plugin to build Karaf
<dependencies>
<dependency>
<!-- Scope is compile so all features (there is only one) are installed
into startup.properties and
the feature repo itself is not added in
etc/org.apache.karaf.features.cfg file
-->
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<type>kar</type>
<scope>compile</scope>
</dependency>
<dependency>
<!-- Scope is runtime so the feature repo is listed
in etc/org.apache.karaf.features.cfg file,
and features will installed into the system directory.
This imports the standard Karaf features described at https://repo1.maven.org/maven2/org/apache/karaf/features/standard/3.0.4/standard-3.0.4-features.xml
These features are installed in the karaf-maven-plugin configuration
-->
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<karafVersion>${karaf.version}</karafVersion>
<!-- bootFeatures starts up these features when Karaf first boots up.
The feature names are obtained from the features.xml in the
dependencies section
-->
<bootFeatures>
<feature>standard</feature>
<feature>config</feature>
<feature>ssh</feature>
</bootFeatures>
<!-- installedFeatures only installs the libraries but the user will
have to start it up manually via Karaf command line feature:install
-->
<installedFeatures>
<feature>scheduler</feature>
<feature>war</feature>
</installedFeatures>
</configuration>
</plugin>
</plugins>
</build>
See https://github.com/juttayaya/karaf/blob/master/karaf3/custom-karaf/custom-karaf-server/pom.xml for full example.
Step 3: Create customized logo
You can customize the logo displayed when users first log in via command line
A.) Create the file src/main/resources/org/apache/karaf/branding/branding.properties
This file configures the welcome logo and command prompt.
See https://github.com/juttayaya/karaf/blob/master/karaf3/custom-karaf/custom-karaf-branding/src/main/resources/org/apache/karaf/branding/branding.properties for full example.
B.) Configure maven-bundle-plugin to create an OSGi bundle with the branding.properties file. Add the following entry in the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*</Import-Package>
<Private-Package>!*</Private-Package>
<Export-Package>org.apache.karaf.branding</Export-Package>
<Spring-Context>*;public-context:=false</Spring-Context>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
The maven-bundle-plugin creates a JAR file with a META-INF/MANIFEST.MF and branding.properties .
See https://github.com/juttayaya/karaf/blob/master/karaf3/custom-karaf/custom-karaf-branding/pom.xml for full example.
C.) Configure maven-dependency-plugin to copy the branding JAR created in step B into the Karaf lib directory. Add the following entry to the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>copy</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>custom-karaf-branding</artifactId>
<version>${project.version}</version>
<!-- target/assembly is the directory karaf-maven-plugin
assembles all the files of the Karaf server -->
<outputDirectory>target/assembly/lib</outputDirectory>
<destFileName>custom-karaf-branding.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
See https://github.com/juttayaya/karaf/blob/master/karaf3/custom-karaf/custom-karaf-server/pom.xml for full example.
Step 4: Build it
Run mvn clean install
The output file is target/custom-karaf-server.tar.gz and target/custom-karaf-server.zip
No comments:
Post a Comment