问题描述
我正在尝试将Apache Felix File Install
与Felix的嵌入式版本一起使用.基本思想很简单,我有一个jar应用程序文件,可以使用标准java -jar app.jar
启动该应用程序,该应用程序将启动Apache Felix框架,然后查看hot deploy
文件夹,以安装,更新和删除/在运行时从该文件夹中放置/更新/删除.
I am trying to use Apache Felix File Install
with an embedded version of Felix. The basic idea is simple, I have a jar application file that can be launched using standard java -jar app.jar
and the application will startup Apache Felix framework and then look in a hot deploy
folder installing, updating and removing the OSGi bundles that are in/placed/updated/removed from that folder at runtime.
我目前已经设法创建了启动嵌入式Felix的功能,并且如果我通过BundleContext.installBundle()
指定了捆绑包,则可以部署捆绑包,但是我无法从热文件夹中动态获取jar
捆绑包.
I currently have managed to create the ability to startup the embedded Felix and I can deploy bundles if I specify them via BundleContext.installBundle()
but I cant get the jar
bundles to be dynamically harvested from the hot folder.
这是我目前拥有的:
public static void main(String[] args) throws Exception {
System.setProperty("felix.fileinstall.noInitialDelay", "true");
System.setProperty("felix.fileinstall.poll", "1000");
System.setProperty("felix.fileinstall.dir", "./hot-deploy");
System.out.println("Building OSGi Framework");
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<>();
// make sure the cache is cleaned
config.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
// more properties available at: http://felix.apache.org/documentation/subprojects/apache-felix-service-component-runtime.html
config.put("ds.showtrace", "true");
config.put("ds.showerrors", "true");
Framework framework = frameworkFactory.newFramework(config);
framework.start();
// declarative services dependency is necessary, otherwise they won't be picked up!
loadScrBundle(framework);
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<>();
//installedBundles.add(context.installBundle("file:./Sandbox/osgiTest/module-a/target/module-a-1.0-SNAPSHOT.jar"));
for (Bundle bundle : installedBundles) {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
bundle.start();
}
}
try {
framework.waitForStop(0);
} finally {
System.exit(0);
}
}
private static void loadScrBundle(Framework framework) throws URISyntaxException, BundleException {
URL url = Activator.class.getClassLoader().getResource("org/apache/felix/scr/ScrService.class");
if (url == null) {
throw new RuntimeException("Could not find the class org.apache.felix.scr.ScrService");
}
String jarPath = url.toURI().getSchemeSpecificPart().replaceAll("!.*", "");
System.out.println("Found declarative services implementation: " + jarPath);
framework.getBundleContext().installBundle(jarPath).start();
}
推荐答案
事实证明,felix.fileinstall
本身是一个捆绑软件,必须在主机应用程序中启动才能查看目录.从最初的实施到开始工作,只需安装并启动fileinstall
捆绑包:
Turns out that felix.fileinstall
itself is a bundle that must be started in the host application before it can watch a directory. All that is required from my initial implementation to work is to install and start the fileinstall
bundle:
installedBundles.add(context.installBundle("file:path/to/fileinstall.jar"));
这篇关于Apache Felix File从deploy文件夹安装jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!