【问题标题】:Apache Felix FileInstall won't workApache Felix FileInstall 不起作用
【发布时间】:2015-04-23 22:57:17
【问题描述】:

我正在尝试将 FileInstall 工件设置到我的 OSGi 项目,但没有成功。任何文件夹下都没有加载任何包。

首先我在这个位置运行 Felix 框架(使用 framework.properties 文件或配置文件):

org.osgi.framework.storage=./target/osgi-runner

然后我将 FileInstall dir 属性添加到框架配置中,如下所示:

felix.fileinstall.dir=./deploy
org.osgi.framework.storage=./target/osgi-runner

文档没有说的是两个文件夹之间的关系,./deploy文件夹应该在哪里:

|--deploy // here?
|--target
      |--osgi-runner

|--target
      |--osgi-runner
      |--deploy  // here?

|--target
      |--osgi-runner
               |--deploy  //or here?

我告诉你,我尝试了所有免费的,但都没有工作,这个 FileInstall 工件没有加载任何包。该工件默认使用 2 秒来检查文件夹,但无论您等待多长时间,它都无法完成工作。

我也一直在考虑开发我自己版本的这个神器,实际上它并没有那么复杂,但是如果我能让这个东西工作起来,节省一些时间和精力也是可以的。

有人,有什么想法吗?

【问题讨论】:

    标签: osgi apache-felix


    【解决方案1】:

    我终于搞定了。 /deploy 文件夹必须在 /osgi-runner 旁边。问题是,当我使用此功能运行 Arquillian 测试时,我没有等待足够长的时间让工件采取行动,我使用了 4 秒的计时器,因此将其增加到 10 并开始显示控制台消息 @987654323 @ 表示服务已经加载了一个bundle。

    我在 Arquillian OSGi 中使用以下测试用例配置:

    framework.properties我有:

    felix.fileinstall.dir=./target/load
    

    而Test-Case的实现如下:

    @RunWith(Arquillian.class)
    public class GreeterFileCnfTestCase {
        static final String FileInstall = "org.apache.felix.fileinstall-3.4.2.jar";
    
        @Deployment(name = FileInstall, testable = false)
        public static Archive<?> deploymentD() {
            return ShrinkWrap.create(ZipImporter.class, FileInstall)
                           .importFrom(new File("/path/to/apache.felix.fileinstall/" + FileInstall))
                           .as(JavaArchive.class);
        }
    
        @ArquillianResource
        BundleContext context;
    
        @Test
        public void fileConfigServices() throws Exception {
            Bundle fiBundle = context.getBundle(FileInstall);
            assertEquals("Bundle ACTIVE", Bundle.ACTIVE, fiBundle.getState());
    
            String fileName = "/bundle.test-1.0.0.jar";
            String dstFolder = "target/load";
            new File(dstFolder).mkdir();
    
            File srcBundle = new File("/path/to/bundle.test-1.0.0" + fileName);
            File dstBundle = new File(dstFolder + fileName);
    
            FileUtils.copyDirectory(srcBundle, dstBundle);
    
            TimeUnit.SECONDS.sleep(5);
            Bundle bundleTest = context.getBundle(dstBundle.toURI().toString());
            assertNotNull(bundleTest);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-26
      • 1970-01-01
      • 2013-07-16
      • 2012-09-27
      • 2020-09-29
      • 2016-12-25
      • 1970-01-01
      • 2019-01-28
      • 2018-05-14
      相关资源
      最近更新 更多