从OSGI包依赖
我已经将maven-bundle-plugin
恢复为使用默认值。这是我现在的照片:
<?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.felix.test</groupId>
<artifactId>com.felix.test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.9.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-osgi</artifactId>
<version>4.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
所有的包和安装OK。当我尝试启动包时,我被告知我丢失了我安装的net.sf.ehcache
。然后我错过了我安装的slf4j.api
。然后我错过了slf4j.impl
,我已经尝试安装几乎每一个slf4j.impl
的可能性从https://jpm4j.org/#!/但大多数(slf4j-simple-1.7.12.jar
, slf4j-log4j12-1.7.12.jar
)报告:
org.osgi.framework.BundleException: Fragment bundles can not be开始。
这是我的当前错误从GoGo:
org.osgi.framework.BundleException:无法解析com.felix.test[16](R 16.0):缺失需求[com.felix.]测试[16](R 16.0)]osgi.wiring.package;(, (osgi.wiring.package = net.sf.ehcache)(> = 2.10.0版)(!(> = 3.0.0版本)))[原因]:无法解析net.sf.ehcache [17](r17.0): missing(net.sf要求。[17](R 17.0)] osgi.wiring.package;(, (osgi.wiring.package = org.slf4j)(> = 1.7.0版)(!(> = 2.0.0版本)))[原因]:无法解析slf4j。api [23](R 23.0):缺失(slf4j要求。[23](R 23.0)] osgi.wiring.package;(, (osgi.wiring.package = org.slf4j.impl)(> = 1.6.0)版)]]悬而未决要求:[[com.felix。[16](r16.0)] osgi.wiring.package(, (osgi.wiring.package = net.sf.ehcache)(> = 2.10.0版)(!(> = 3.0.0版本))))
希望我离你越来越近…
谢谢!
您有两个错误需要解决。第一个是"无法启动片段包"。错误消息告诉您需要知道的一切。slf4j实现包是片段,您不能启动片段。所以千万不要开始!
您没有指定如何运行OSGi框架,但是在某个地方您必须有一些代码遍历所有已安装的包并调用每个包的start()
方法。您需要修改您的代码,以避免在作为片段的bundle上调用start()
。你可以这样判断bundle是否为fragment:
(bundle.adapt(BundleRevision.class).getTypes() | BundleRevision.TYPE_FRAGMENT) > 0;
或者:
bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
第二个错误说名为com.felix.test
的包依赖于net.sf.ehcache
包。我从来没有听说过com.felix.test
…这是你正在构建的包吗?你真的在你的代码中使用Ehcache吗?如果是这样,显然需要安装Ehcache包。如果你安装了Ehcache,那么它可能是错误的版本;你的bundle需要2.10.0到3.0.0版本,但不包括3.0.0。