Karaf 4.0.4:自定义分发 - karaf-maven-plugin

Karaf 4.0.4: Custom distribution - karaf-maven-plugin

我正在尝试通过向启动功能添加 eventadminscr 功能来构建自定义分发。

我已经根据 http://karaf.apache.org/manual/latest/developers-guide/custom-distribution.html 的官方文档尝试了以下方法。

我创建了一个新项目 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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.jemz.jf.karaf</groupId>
<artifactId>jf-framework-karaf</artifactId>
<packaging>karaf-assembly</packaging>
<name>${project.artifactId}</name>

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

    <dependency>
        <groupId>org.apache.karaf.features</groupId>
        <artifactId>standard</artifactId>
        <version>4.0.4</version>
        <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>
            <version>4.0.4</version>
            <extensions>true</extensions>
            <configuration>
                <!-- no startupFeatures -->
                <startupFeatures>
                    <feature>eventadmin</feature>
                    <feature>scr</feature>
                </startupFeatures>

                <installedFeatures>
                </installedFeatures>
                <bootFeatures>
                    <feature>standard</feature>
                </bootFeatures>

                <excludedArtifactIds>
                    <artifactId>slf4j-api</artifactId>
                </excludedArtifactIds>
            </configuration>
        </plugin>
    </plugins>
</build>

不幸的是,当我 运行 'mvn install' 它失败了:

[ERROR] Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.0.4:assembly (default-assembly) on project jf-framework-karaf: Unable to build assembly: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=scr; type=karaf.feature; filter:="(&(osgi.identity=scr)(type=karaf.feature))" -> [Help 1]

如果我将 'eventadmin' 和 'scr' 功能移动到 'bootFeatures',虽然这不是我最初想要的,但自定义 karaf 发行版组装正常,但是当我启动它时 returns 部分例外情况如下图:

jmartinez@archlinux-dev-64 target]$ ./jf-framework-karaf-3.0.0-SNAPSHOT/bin/karaf 
        __ __                  ____      
       / //_/____ __________ _/ __/      
      / ,<  / __ `/ ___/ __ `/ /_        
     / /| |/ /_/ / /  / /_/ / __/        
    /_/ |_|\__,_/_/   \__,_/_/         

  Apache Karaf (4.0.4)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.

karaf@root()> org.apache.karaf.features.core[org.apache.karaf.features.internal.service.BootFeaturesInstaller] : Error installing boot features
org.apache.karaf.features.internal.util.MultiException: Error restarting bundles
    at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:848)
    at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1089)
    at org.apache.karaf.features.internal.service.FeaturesServiceImpl.call(FeaturesServiceImpl.java:985)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Suppressed: org.osgi.framework.BundleException: Activator start error in bundle org.ops4j.pax.url.wrap [55].
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
        at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1199)
        at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:840)
        ... 6 more
    Caused by: java.lang.IllegalStateException: Unknown protocol: mvn
        at org.apache.felix.framework.URLHandlersStreamHandlerProxy.toExternalForm(URLHandlersStreamHandlerProxy.java:482)
        at org.apache.felix.framework.URLHandlersStreamHandlerProxy.toExternalForm(URLHandlersStreamHandlerProxy.java:474)
        at java.net.URL.toExternalForm(URL.java:922)
        at java.net.URL.toString(URL.java:908)
        at java.lang.ClassLoader.defineClassSourceLocation(ClassLoader.java:675)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:759)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
        at org.apache.felix.framework.BundleWiringImpl.access0(BundleWiringImpl.java:79)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1415)
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4468)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2221)
        ... 11 more
    Suppressed: org.osgi.framework.BundleException: Activator start error in bundle org.apache.felix.metatype [21].
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
        at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1199)
        at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:840)
        ... 6 more
    Caused by: java.lang.IllegalStateException: Unknown protocol: mvn
        at org.apache.felix.framework.URLHandlersStreamHandlerProxy.toExternalForm(URLHandlersStreamHandlerProxy.java:482)
        at org.apache.felix.framework.URLHandlersStreamHandlerProxy.toExternalForm(URLHandlersStreamHandlerProxy.java:474)
        at java.net.URL.toExternalForm(URL.java:922)
        at java.net.URL.toString(URL.java:908)
        at java.lang.ClassLoader.defineClassSourceLocation(ClassLoader.java:675)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:759)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
        at org.apache.felix.framework.BundleWiringImpl.access0(BundleWiringImpl.java:79)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1415)
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4468)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2221)
        ... 11 more
    Suppressed: org.osgi.framework.BundleException: Activator start error in bundle org.apache.karaf.services.eventadmin [45].
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
        at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1199)
        at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:840)
        ... 6 more
    Caused by: java.lang.IllegalStateException: Unknown protocol: mvn
        at org.apache.felix.framework.URLHandlersStreamHandlerProxy.toExternalForm(URLHandlersStreamHandlerProxy.java:482)
        at org.apache.felix.framework.URLHandlersStreamHandlerProxy.toExternalForm(URLHandlersStreamHandlerProxy.java:474)
        at java.net.URL.toExternalForm(URL.java:922)
        at java.net.URL.toString(URL.java:908)
        at java.lang.ClassLoader.defineClassSourceLocation(ClassLoader.java:675)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:759)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
        at org.apache.felix.framework.BundleWiringImpl.access0(BundleWiringImpl.java:79)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1415)
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4468)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2221)
        ... 11 more
The specified feature: 'standard' version '4.0.4' is already installed
The specified feature: 'scr' version '4.0.4' is already installed
The specified feature: 'eventadmin' version '4.0.4' is already installed
^C
karaf@root()> ^Dkaraf@root()>

尽管一切都已安装并启动正常。重新启动后,所有异常都消失并且工作正常。

我的问题是:

  1. 如何在 eventadmin 和 scr
    中创建自定义分发 功能在启动时启动 (startup.properties)?
  2. 如果在 bootFeatures 上设置了 eventadmin/scr 功能,我如何才能在第一次启动时摆脱这些异常?

附带说明一下,我已经能够使用已弃用的旧式 Maven 程序集设置稳定的自定义分发,但使用 karaf-maven-plugin 的新方法似乎要容易得多。

从 Karaf 标准功能中删除运行时范围:

<dependency>
    <groupId>org.apache.karaf.features</groupId>
    <artifactId>standard</artifactId>
    <version>4.0.4</version>
    <classifier>features</classifier>
    <type>xml</type>
</dependency>

此范围阻止将 eventadmin/scr 所需的某些捆绑包添加到启动阶段。 tbh,我不太清楚这里使用的解析器的所有方面以及不同的阶段和配置文件来生成程序集,但是删除这个范围使其工作