我正在尝试通过将 eventadmin 和 scr 功能添加到启动功能来构建自定义分发。
我根据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&#39;它失败了:
[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]
如果我移动&#39; eventadmin&#39;并且&#39; scr&#39;虽然这不是我原来想要的功能,但自定义karaf发行版组合好了,但是当我开始它时会返回一些例外情况,如下所示:
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$1.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.access$400(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.access$400(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.access$400(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()>
尽管一切都已安装并且已开始正常。重启后,所有异常都会消失并正常工作。
我的问题是:
作为旁注,我已经能够使用已弃用的旧式Maven程序集来设置稳定的自定义分发,但使用karaf-maven-plugin的新方法似乎更加轻松。
答案 0 :(得分:4)
从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所需的某些bundle添加到启动阶段。 tbh,我不清楚这里使用的解析器的所有方面都有不同的阶段和配置文件来生成一个程序集,但删除这个范围使它工作