由于以下异常,无法启动/停止osgi bundle programaticallly ....

时间:2013-12-10 13:43:19

标签: java eclipse osgi-bundle

符号名称ram

  

线程“main”中的异常org.osgi.framework.BundleException:   bundle ram [1]中未解决的约束:无法解析1.0:   缺少要求[1.0] osgi.wiring.package;   (osgi.wiring.package = android.dalvik)at   org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)     在org.apache.felix.framework.Felix.startBundle(Felix.java:1868)at   org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)at at   org.apache.felix.framework.BundleImpl.start(BundleImpl.java:931)at at   test9.Shulkam_Demo.main(Shulkam_Demo.java:35)

我的代码是..

import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;

public class Shulkam_Demo {

public static void main(String[] args) throws Exception{
    // TODO Auto-generated method stub

    FrameworkFactory frameworkFactory =    ServiceLoader.load(FrameworkFactory.class).iterator().next();
    Map<String, String> config = new HashMap<String, String>();
    //TODO: add some config properties
    Framework framework = frameworkFactory.newFramework(config);
    framework.start();
    //System.out.println(framework.getSymbolicName());

    //framework.start();

   //System.out.println( "bundle id" +framework.getBundleId());
    BundleContext bc = framework.getBundleContext();

    Bundle b = bc.installBundle("file:C:\\Documents and Settings\\Rishika Inc   Lab\\Desktop\\delete12\\shulkam_accounts-0.0.1-SNAPSHOT.jar");

    System.out.println("symbolic name "+b.getSymbolicName());
    b.start();
    System.out.println("frame work started");

    framework.waitForStop(0);

    System.out.println("shut dow");

}  

和build.xml是

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>shulkam_accounts</groupId>
<artifactId>shulkam_accounts</artifactId>
<packaging>bundle</packaging>

<version>0.0.1-SNAPSHOT</version>
<properties>

<springdm.version>1.1.2</springdm.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.4.0</version>
    <extensions>true</extensions>
    <configuration>

    <instructions>
    <Export-Package>*</Export-Package>
    <Embed-Dependency>*</Embed-Dependency>
    <Embed-Transitive>true</Embed-Transitive>
    <Bundle-SymbolicName>ram</Bundle-SymbolicName>
    <Import-package>
    com.mysql.jdbc;version="5.1.15",
 org.osgi.framework;version="1.3.0",
!osgi.wiring.package,
!android.dalvik



 </Import-package>
<Bundle-Activator>shulkam_accounts.MyActivator</Bundle-Activator>


    </instructions>
    </configuration>
  </plugin>
  </plugins>
 </build>
 <dependencies>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.15</version>
</dependency>
<!-- Spring DM -->


    <dependency>
      <groupId>org.springframework.osgi</groupId>
      <artifactId>spring-osgi-io</artifactId>
      <version>${springdm.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.osgi</groupId>
      <artifactId>spring-osgi-core</artifactId>
      <version>${springdm.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.osgi</groupId>
      <artifactId>spring-osgi-extender</artifactId>
      <version>${springdm.version}</version>
      <scope>provided</scope>
    </dependency>

  <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.apache.felix.framework</artifactId>
        <version>4.0.2</version>
         <scope>provided</scope>
    </dependency>
    <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>


</dependencies>
</project>

任何可以理解的帮助...

2 个答案:

答案 0 :(得分:0)

我认为

<Export-Package>*</Export-Package>

是原因。使用

<Export-Package></Export-Package> 

除非您实际导出某些内容。

答案 1 :(得分:0)

你有一个缺少依赖的问题:

missing requirement [1.0] osgi.wiring.package (osgi.wiring.package=android.dalvik)

并且您已指定您不想在import-package中使用它:

<Import-package>
com.mysql.jdbc;version="5.1.15",
org.osgi.framework;version="1.3.0",
!osgi.wiring.package,
!android.dalvik

要获得它,您应该在Import-Package中使用它。