felix学习二-发布classpath为bundle

    这次我们需要将classpath中的jar发布成bundle。

    我们在Main中找到main这个启动函数,同样可以发现loadSystemProperties这个配置加载函数,他负责加载config.properties中的felix一个配置属性。其中felix.auto.start.1是bundle物理路径的配置参数。如果我们想启动某一个bundle可以通过修改该属性值实现。现在我们要做的是自动让eclipse工程中classpath里面的jar发布为felix中的bundle。实现也是考虑修改felix.auto.start.1的值。所以我们在loadSystemProperties方法后面增加一些代码,如下:

 

// jar
  String jarBundles = (String) props.get("felix.auto.start.1");

  String[] classpathJars = System.getProperty("java.class.path").split(
    ";");
  for (String location : classpathJars) {

   if (!location.contains("test")) {
    String jarName = location
      .substring(location.lastIndexOf("\\") + 1);
    if (jarName.indexOf("jar") > 0) {
      if (jarName.contains("org.apache.felix.framework")) {
      continue;
     }
     if (!jarBundles.contains(jarName)) {
      location.replaceAll("/", "\\");
      jarBundles = jarBundles + " file:" + location;
     }
    } else {
     // 文件夹方式
     File manifestFile = new File(location+ "/META-INF/Manifest.mf");
     if (manifestFile.exists()) {
      jarBundles = jarBundles + " reference:file:" + location;
     }
    }

   }
  }

  props.setProperty("felix.auto.start.1", jarBundles);

 

现在我们可以将classpath中的jar和工程都发布为bundle啦。可以随便写一个测试用例。在main的pom.xml中添加一个依赖。启动完后ps一下你会发现这个符合bundle的依赖已经发布成bundle啦。

 

  附上修改后的Main.java。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值