【发布时间】:2018-02-20 22:33:11
【问题描述】:
这对我来说太新鲜了,而且有点复杂。我在 Eclipse 中使用标准 OSGi 框架创建了一个插件项目。目的是使用此捆绑包连接到 H2 DB。这是 Activator.java: 打包数据库服务;
import java.sql.Connection;
import java.sql.DriverManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private static BundleContext context;
private Connection conn=null;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Class.forName("org.h2.Driver");
conn = DriverManager.getConnection("jdbc:h2:~/test","sa","123456");
System.out.print("Connection opened...");
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
conn.close();
System.out.print("Connection closed...");
}
}
我在 OSGi 框架中运行这个项目。它在那里工作。但我的问题是,如何在另一个项目中使用这个捆绑包?
【问题讨论】: