【发布时间】:2019-06-01 23:44:13
【问题描述】:
无法将包加载到 felix。我下载了 Felix 6.0.1,使用
运行> java -jar bin/felix.jar
____________________________
Welcome to Apache Felix Gogo
g!
我在 Eclipse 中创建了一个 MavenProject TestA:
- 我按照提供的方式向 felix (6.0.1) 添加了一个依赖项。
- 我在
TestA/src/main/java/testa/impl/Activator.java中创建了一个类。 - 我将
testa.impl.Activator类扩展为org.osgi.framework.BundleActivator。 - 我覆盖
public void start(BundleContext bc) throws Exception以打印出Hello World!。
这是java源码:
package testa.impl;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext arg0) throws Exception {
System.out.println("Hello World!");
}
public void stop(BundleContext arg0) throws Exception {
System.out.println("stop");
}
}
这是我的pom.xml:
<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>test</groupId>
<artifactId>testa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>6.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install org.apache.felix:maven-bundle-plugin:bundle</defaultGoal>
</build>
</project>
然后我使用 mvn 编译到 jar 并使用
g! install file:/C:/xxx/TestA/target/testa-0.0.1-SNAPSHOT.jar
Bundle ID: 20
然后我使用lb列出所有捆绑包
g! lb 15:51:56
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (6.0.1)|6.0.1
1|Active | 1|jansi (1.17.1)|1.17.1
2|Active | 1|JLine Bundle (3.7.0)|3.7.0
3|Active | 1|Apache Felix Bundle Repository (2.0.10)|2.0.10
4|Active | 1|Apache Felix Gogo Command (1.0.2)|1.0.2
5|Active | 1|Apache Felix Gogo JLine Shell (1.1.0)|1.1.0
6|Active | 1|Apache Felix Gogo Runtime (1.1.0)|1.1.0
20|Installed | 1|testa (0.0.1.SNAPSHOT)|0.0.1.SNAPSHOT
g!
无论如何,我使用start 启动捆绑包:
g! start 20
g!
我预计会打印“Hello World”,但 什么都没有显示出来!
我现在很困惑,并尝试找出捆绑包是否真的开始了。
g! lb 15:51:56
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (6.0.1)|6.0.1
1|Active | 1|jansi (1.17.1)|1.17.1
2|Active | 1|JLine Bundle (3.7.0)|3.7.0
3|Active | 1|Apache Felix Bundle Repository (2.0.10)|2.0.10
4|Active | 1|Apache Felix Gogo Command (1.0.2)|1.0.2
5|Active | 1|Apache Felix Gogo JLine Shell (1.1.0)|1.1.0
6|Active | 1|Apache Felix Gogo Runtime (1.1.0)|1.1.0
20|Active | 1|testa (0.0.1.SNAPSHOT)|0.0.1.SNAPSHOT
g! 15:51:58
它已启动,但我的代码尚未执行。
问题
为什么控制台上没有打印Hello World?
【问题讨论】:
-
检查记录器配置
-
@jhamon 记录器配置正确。
标签: java maven osgi apache-felix