Frédéric
Frédéric

Reputation: 583

Karaf Maven Plugin : features provisioning

I would like to leverage on the Karaf Maven Plugin to prepare an assembly with a recent version of Jetty.
This assembly will be deployed in Docker.
And I'll add on top of it my custom features.

However I'm struggling to figure out how to have the org.eclipse.jetty.feature version 11.0.18 maven feature that I've defined, hereby below.
Recorded in src/main/feature/feature.xml

<features name="org.eclipse.jetty.features-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.6.0 http://karaf.apache.org/xmlns/features/v1.6.0">
    <feature name="org.eclipse.jetty.feature" version="11.0.18">
        <bundle>mvn:org.osgi/org.osgi.service.component/1.5.1</bundle>
        <bundle>mvn:jakarta.activation/jakarta.activation-api/2.1.2</bundle>
        <bundle>mvn:jakarta.annotation/jakarta.annotation-api/2.1.1</bundle>
        <bundle>mvn:jakarta.mail/jakarta.mail-api/2.1.2</bundle>
        <bundle>mvn:jakarta.servlet/jakarta.servlet-api/5.0.0</bundle>
        <bundle>mvn:jakarta.inject/jakarta.inject-api/2.0.1</bundle>
        <bundle>mvn:jakarta.interceptor/jakarta.interceptor-api/2.1.0</bundle>
        <bundle>mvn:jakarta.el/jakarta.el-api/4.0.0</bundle>
        <bundle>mvn:jakarta.enterprise/jakarta.enterprise.cdi-api/3.0.1</bundle>
        <bundle>mvn:jakarta.security.auth.message/jakarta.security.auth.message-api/2.0.0-RC1</bundle>
        <bundle>mvn:jakarta.transaction/jakarta.transaction-api/2.0.1</bundle>
        <bundle>mvn:org.ow2.asm/asm/9.6</bundle>
        <bundle>mvn:org.ow2.asm/asm-tree/9.6</bundle>
        <bundle>mvn:org.ow2.asm/asm-analysis/9.6</bundle>
        <bundle>mvn:org.ow2.asm/asm-commons/9.6</bundle>
        <bundle>mvn:org.ow2.asm/asm-util/9.6</bundle>
        <bundle>mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/1.3.6</bundle>
        <bundle>mvn:org.eclipse.jetty.toolchain/jetty-jakarta-websocket-api/2.0.0</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-util/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-util-ajax/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-jmx/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-io/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-http/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-server/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-security/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-servlet/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-servlets/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-alpn-client/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-client/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-xml/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-webapp/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-deploy/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-jaas/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-jndi/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-plus/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-proxy/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-rewrite/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-jaspi/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty/jetty-annotations/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-jetty-api/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-core-common/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-jetty-common/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-core-server/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-servlet/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-jetty-server/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-core-client/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-core-common/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-jakarta-common/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-jakarta-client/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/websocket-jakarta-server/11.0.18</bundle>
        <bundle>mvn:org.eclipse.jetty.websocket/jetty-osgi-boot/11.0.18</bundle>
    </feature>
</features>

And here is my main 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>com.example</groupId>
    <artifactId>com.example.dockerization</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <karaf.version>4.4.5</karaf.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>framework</artifactId>
            <version>${karaf.version}</version>
            <type>kar</type>
        </dependency>

        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>framework</artifactId>
            <version>${karaf.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>standard</artifactId>
            <version>${karaf.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
        </dependency>
    </dependencies>
    
    <build>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/feature</directory>
                <filtering>true</filtering>
                <targetPath>${project.build.directory}/feature</targetPath>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.karaf.tooling</groupId>
                <artifactId>karaf-maven-plugin</artifactId>
                <version>${karaf.version}</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>process-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>package</id>
                        <goals>
                            <goal>archive</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>dockerfile</id>
                        <goals>
                            <goal>dockerfile</goal>
                        </goals>
                        <configuration>
                            <command>["karaf", "run"]</command>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <installedFeatures>
                    </installedFeatures>
                    <startupFeatures>
                        <feature>eventadmin</feature>
                    </startupFeatures>
                    <bootFeatures>
                        <feature>feature</feature>
                        <feature>shell</feature>
                        <feature>deployer</feature>
                        <feature>bundle</feature>
                        <feature>config</feature>
                        <feature>diagnostic</feature>
                        <feature>instance</feature>
                        <feature>jaas</feature>
                        <feature>log</feature>
                        <feature>package</feature>
                        <feature>service</feature>
                        <feature>system</feature>
                        <feature>kar</feature>
                        <feature>ssh</feature>
                        <feature>management</feature>
                        <feature>pax-url-wrap</feature>
                        <feature>wrap</feature>
                        <feature>org.eclipse.jetty.feature</feature>
                    </bootFeatures>
                    <javase>17</javase>
                    <propertyEdits>
                        <edits>
                            <edit>
                                <file>config.properties</file>
                                <operation>
                                    <operation>put</operation>
                                </operation>
                                <key>karaf.framework</key>
                                <value>equinox</value>
                            </edit>
                        </edits>
                    </propertyEdits>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>target/feature/feature.xml</file>
                                    <classifier>features</classifier>
                                    <type>xml</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>docker</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.karaf.tooling</groupId>
                        <artifactId>karaf-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>docker-image</id>
                                <goals>
                                    <goal>docker</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>${project.artifactId}</imageName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.karaf.tooling</groupId>
                        <artifactId>karaf-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>process-resources</id>
                                <phase>none</phase>
                            </execution>
                            <execution>
                                <id>package</id>
                                <phase>none</phase>
                            </execution>
                            <execution>
                                <id>dockerfile</id>
                                <phase>none</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

Maven (3.9.6) build instruction: mvn clean install

So what am I missing in my main pom.xml to have the custom org.eclipse.jetty.feature deployed in the resulting Assembly?

P.S. I'm using Eclipse Equinox instead of Apache Felix as OSGi system bundle.

P.P.S. zsh command to list all the jars and their version in the target folder ... no Jetty jars listed 😟

(for f in $(ls -1 target/**/*.jar); do unzip -p $f META-INF/MANIFEST.MF | grep -E '(Bundle-SymbolicName|Bundle-Version)' | tr -d '\r' | sort | sed -E 's/^Bundle-(Version|SymbolicName): //;s/;.*//' | paste -d ':' - -; done) | sort -u

Upvotes: 1

Views: 65

Answers (0)

Related Questions