【发布时间】:2013-07-26 20:39:03
【问题描述】:
我有一个从 jar 文件 (testlibrary.jar) 调用代码的 OSGI 包 (awesome.test)。我已将该捆绑包作为 Liberty 功能 (awesome.test.feature) 包含在内,并将它安装在 WebSphere Application Server Liberty Profile V8.5.5 上。我还有一个 OSGI 包 (awesometest),它是 OSGI 应用程序 (awesometest.app) 的一部分,它有一个 Activator 类。
Here is a picture of my workspace setup
我想做的是通过 awesome.test 中的方法调用 testlibrary.jar 中的方法,其中包括 testlibrary.jar 在其构建路径中。我的 awesome.test.feature 可用于在我的 Liberty 服务器上运行的任何应用程序。我希望我的应用程序能够使用该功能通过我在 awesome.test 中提供的功能来访问 testlibrary.jar 中的功能。我不希望 OSGI 应用程序直接从 testlibrary.jar 导入包。
当我在服务器上运行应用程序时,二进制日志中出现以下错误:
CWWKZ0402E: 尝试将应用程序 awesometest.app 安装到 OSGi 框架中时生成了捆绑异常。来自 OSGi 框架的错误文本是:Exception in awesometest.Activator.start() of bundle awesometest。
调试问题发现抛出了这个异常:
java.lang.ClassNotFoundException: testlibrary.test.TestAPI
来自 Awesome.test 中的 TestLibraryRunner.java:
package awesome.test;
import testlibrary.test.TestAPI;
public class TestLibraryRunner {
public static void runNonLibTest() {
System.out.println("No Library code is being called");
}
public static void runLibTest() {
TestAPI ta = new TestAPI("This is a message.");
ta.display();
}
}
请注意,从 OSGI 应用程序调用时,runNonLibTest() 将起作用。从 OSGI 应用程序调用 runLibTest 中的 TestAPI 代码会导致上述错误。
来自 Awesometest 中的 Activator.java:
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
System.out.println("Starting...");
TestLibraryRunner.runNonLibTest();
TestLibraryRunner.runLibTest();
System.out.println("Finishing...");
}
public void stop(BundleContext context) throws Exception {
System.out.println("Stopping...");
}
}
来自 awesometest 中的 MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: awesometest
Bundle-SymbolicName: awesometest
Bundle-Version: 1.0.0
Bundle-Activator: awesometest.Activator
Import-Package: awesome.test,
org.osgi.framework
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: awesometest
总之,我的 OSGI 应用程序无法访问我的 Liberty 功能中包含的包的构建路径中的 jar 中的代码。我在这里缺少一些基本的东西吗?我正在尝试做的事情是否可能?
谢谢
【问题讨论】: