java.util.NoSuchElementException while starting an OSGi framework programatically -


i trying programatically start osgi framework (preferably equinox) java , load bundles.

so going through article says how that. getting java.util.nosuchelementexception everytime @ below line everytime

serviceloader.load(frameworkfactory.class).iterator().next(); 

below code-

import java.io.file; import java.util.hashmap; import java.util.linkedhashmap; import java.util.map; import java.util.serviceloader; import java.util.logging.logger;  import org.osgi.framework.bundle; import org.osgi.framework.bundlecontext; import org.osgi.framework.bundleexception; import org.osgi.framework.frameworkutil; import org.osgi.framework.launch.framework; import org.osgi.framework.launch.frameworkfactory;  public app() {            try {          frameworkfactory frameworkfactory = serviceloader.load(frameworkfactory.class).iterator().next();         map<string, string> config = new hashmap<string, string>();         //todo: add config properties         framework framework = frameworkfactory.newframework(config);         framework.start();              //...  other code          }     } 

i not sure wrong doing here? having maven based project. below pom.xml file project-

<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/maven-v4_0_0.xsd">      <parent>         <groupid>com.host.stream</groupid>         <artifactid>stream-parent</artifactid>         <version>2.0.0-snapshot</version>         <relativepath>../build/superpom</relativepath>     </parent>      <modelversion>4.0.0</modelversion>     <groupid>com.host.domain.eye</groupid>     <artifactid>eye</artifactid>     <packaging>jar</packaging>     <name>eye</name>       <build>         <plugins>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-eclipse-plugin</artifactid>                 <configuration>                     <downloadsources>true</downloadsources>                     <downloadjavadocs>false</downloadjavadocs>                 </configuration>             </plugin>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-jar-plugin</artifactid>                 <configuration>                         <!-- configuration of archiver -->                     <archive>                       <!-- manifest specific configuration -->                         <manifest>                  <!-- classpath added manifest of created jar file. -->                             <addclasspath>true</addclasspath>   <!-- configures classpath prefix. configuration option used                                  specify needed libraries found under lib/ directory. -->                             <classpathprefix>lib/</classpathprefix> <!-- specifies main class of application -->                             <mainclass>com.host.personalization.eye.app</mainclass>                         </manifest>                     </archive>                     <includes>                         <include>**/*.xml</include>                         <include>**/*.class</include>                     </includes>                     <finalname>${project.artifactid}</finalname>                 </configuration>             </plugin>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-resources-plugin</artifactid>                 <executions>                     <execution>                         <phase>prepare-package</phase>                         <goals>                             <goal>copy-resources</goal>                         </goals>                     </execution>                 </executions>                 <configuration>                     <outputdirectory>target/config/streamconf</outputdirectory>                     <resources>                         <resource>                             <directory>buildsrc/streamconf</directory>                             <includes>                                 <include>**</include>                             </includes>                         </resource>                     </resources>                 </configuration>             </plugin>             <plugin>                 <groupid>com.google.code.maven-replacer-plugin</groupid>                 <artifactid>maven-replacer-plugin</artifactid>                 <executions>                     <execution>                         <phase>prepare-package</phase>                         <goals>                             <goal>replace</goal>                         </goals>                     </execution>                 </executions>                 <configuration>                     <file>target/config/streamconf/eyewiring.xml</file>                     <regex>false</regex>                     <replacements>                         <replacement>                             <token>dynamic_build_label_place_holder</token>                             <value>${project.artifactid}-${project.version}-${buildnumber}</value>                         </replacement>                      </replacements>                 </configuration>             </plugin>             <plugin>                 <artifactid>maven-assembly-plugin</artifactid>                 <executions>                     <execution>                         <phase>package</phase>                         <id>assembly</id>                         <goals>                             <goal>single</goal>                         </goals>                         <configuration>                             <descriptors>                                 <descriptor>assembly.xml</descriptor>                             </descriptors>                             <finalname>${project.artifactid}-${project.version}-${buildnumber}</finalname>                         </configuration>                     </execution>                 </executions>             </plugin>             <plugin>                 <groupid>org.apache.felix</groupid>                 <artifactid>maven-bundle-plugin</artifactid>                 <extensions>true</extensions>                 <executions>                     <execution>                         <id>generate-resources</id>                         <goals>                             <goal>manifest</goal>                         </goals>                          <configuration>                         <manifestlocation>buildsrc/streamconf/meta-inf</manifestlocation>                             <instructions>                                 <bundle-name>${project.name}</bundle-name>                                 <bundle-symbolicname>com.host.domain.eye</bundle-symbolicname>                                 <import-package>*,                                     pics,                                     links,                                     javax.el;version="[2.0,3.0)";resolution:=optional,                                     javax.inject;version="[1.0.0,2.0.0)",                                     javax.servlet;version="[2.5,4.0)",                                     javax.servlet.annotation;version="[3.0.0,4.0.0)",                                     javax.servlet.http;version="[2.5,4.0)",                                     javax.servlet.jsp;version="[2.0,3.0)",                                     javax.servlet.jsp.el;version="[2.0,3.0)",                                     org.aopalliance.aop;version="[1.0.0,2.0.0)",                                     org.eclipse.virgo.web.dm;version="[2.1.0.release,3.0)",                                     org.springframework.aop;version="[3.0.5.release,4.0)",                                     org.springframework.aop.framework;version="[3.0.5.release,4.0)",                                     org.springframework.aop.scope;version="[3.0.5.release,4.0)",                                     org.springframework.beans;version="3.0.5.release",                                     org.springframework.beans.annotation;version="[3.0.5.release,4.0)",                                     org.springframework.beans.factory;version="[3.0.5.release,4.0)",                                     org.springframework.beans.factory.annotation;version="[3.0.5.release,4.0)",                                     org.springframework.beans.factory.config;version="[3.0.5.release,4.0)",                                     org.springframework.context;version="[3.0.5.release,4.0)",                                     org.springframework.context.annotation;version="[3.0.5.release,4.0)",                                     org.springframework.context.config;version="[3.0.5.release,4.0)",                                     org.springframework.stereotype;version="[3.0.5.release,4.0)",                                     org.springframework.util;version="[3.0.5.release,4.0)",                                     org.springframework.web.bind.annotation;version="[3.0.5.release,4.0)",                                     org.springframework.web.context;version="[3.0.5.release,4.0)",                                     org.springframework.web.context.request;version="[3.0.5.release,4.0)",                                     org.springframework.web.context.support;version="[3.0.5.release,4.0)",                                     org.springframework.web.servlet;version="[3.0.5.release,4.0)",                                     org.springframework.web.servlet.config;version="[3.0.5.release,4.0)",                                     org.springframework.web.servlet.view;version="[3.0.5.release,4.0)",</import-package>                             </instructions>                         </configuration>                     </execution>                 </executions>             </plugin>         </plugins>     </build>     <dependencies>          <dependency>             <groupid>com.host.stream</groupid>             <artifactid>streamframework</artifactid>             <version>2.0.0-snapshot</version>         </dependency>          <dependency>             <groupid>com.host.external</groupid>             <artifactid>ucirrus-db</artifactid>             <version>0.7.3</version>         </dependency>          <dependency>             <groupid>com.host.stream</groupid>             <artifactid>streamcore</artifactid>             <version>2.0.0-snapshot</version>         </dependency>         <dependency>             <groupid>org.osgi</groupid>             <artifactid>org.osgi.core</artifactid>             <version>4.3.0</version>         </dependency>         <dependency>             <groupid>org.springframework.osgi</groupid>             <artifactid>spring-osgi-core</artifactid>             <version>1.2.1</version>         </dependency>         <dependency>             <groupid>org.springframework.osgi</groupid>             <artifactid>spring-osgi-extender</artifactid>             <version>1.2.1</version>         </dependency>          <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-context</artifactid>             <version>3.2.3.release</version>         </dependency>          <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-aop</artifactid>             <version>3.2.3.release</version>         </dependency>           <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-beans</artifactid>             <version>3.2.3.release</version>         </dependency>           <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-core</artifactid>             <version>3.2.3.release</version>         </dependency>          <dependency>             <groupid>org.springframework.osgi</groupid>             <artifactid>spring-osgi-io</artifactid>             <version>1.2.1</version>         </dependency>         <dependency>             <groupid>org.apache.felix</groupid>             <artifactid>org.osgi.core</artifactid>             <version>1.4.0</version>         </dependency>     </dependencies> </project> 

service loader searches classpath interface have asked -- in case frameworkfactory. fix need put osgi framework implementation on classpath.

for example if choose felix, make sure org.apache.felix.framework-<version>.jar present on classpath when launch application.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo