java - How to add services to desktop Apache Felix application -


i'm new apache felix. want create simple desktop application based on apache felix framework. found this simple example how create simple main method starts framework application i'm not aware how add services application.

package com.paint.servicebased;  import java.util.map; import java.util.serviceloader;  import org.osgi.framework.bundle; import org.osgi.framework.bundlecontext; import org.osgi.framework.bundleexception; import org.osgi.framework.launch.framework; import org.osgi.framework.launch.frameworkfactory;  /**  * class provides static {@code main()} method bundle can  * run stand-alone host application. in such scenario, application  * creates own embedded osgi framework instance , interacts  * internal extensions providing drawing functionality.  * launch stand-alone application, must run bundle's  * installation directory using "{@code java -jar}". locations of  * additional extensions have started, have passed command  * line arguments method.  */ public class application {      private static framework m_framework = null;      /**      * enables bundle run stand-alone application. when static      * {@code main()} method invoked, application creates own      * embedded osgi framework instance , interacts internal      * extensions provide drawing functionality. launch      * stand-alone application, method should invoked bundle's      * installation directory using "{@code java -jar}". location of      * extension shall installed can passed parameters.      * <p>      * example if build bundles inside workspace, maven      * create target directory in every project. start application      * within ide should pass:      * <p>      *      * <pre>      * {@code file:../servicebased.circle/target/servicebased.circle-1.0.0.jar      * file:../servicebased.square/target/servicebased.square-1.0.0.jar      * file:../servicebased.triangle/target/servicebased.triangle-1.0.0.jar}      * </pre>      *      * @param args locations of additional bundles start.      *      */     public static void main(string[] args)     {         // args should never null if application run command         // line.         // check anyway.         string[] locations = args != null ? args : new string[0];          // print welcome banner.         system.out.println("\nwelcome launcher");         system.out.println("======================\n");          try         {             map<string, string> config = configutil.createconfig();             m_framework = createframework(config);             m_framework.init();             m_framework.start();             installandstartbundles(locations);             m_framework.waitforstop(0);             system.exit(0);         }         catch (exception ex)         {             system.err.println("could not create framework: " + ex);             ex.printstacktrace();             system.exit(-1);         }     }      /**      * util method creating embedded framework. tries create      * {@link frameworkfactory} used create framework.      *      * @param config configuration create framework      * @return framework given configuration      */     private static framework createframework(map<string, string> config)     {         serviceloader<frameworkfactory> factoryloader = serviceloader                 .load(frameworkfactory.class);         (frameworkfactory factory : factoryloader)         {             return factory.newframework(config);         }         throw new illegalstateexception(                 "unable load frameworkfactory service.");     }      /**      * installs , starts bundles used application. therefore      * host bundle started. locations of extensions host      * bundle can passed in parameters.      *      * @param bundlelocations locations extension host bundle      * located. must not {@code null}!      * @throws bundleexception if went wrong while installing or      * starting bundles.      */     private static void installandstartbundles(string... bundlelocations)             throws bundleexception     {         bundlecontext bundlecontext = m_framework.getbundlecontext();         activator hostactivator = new activator();         hostactivator.start(bundlecontext);         (string location : bundlelocations)         {             bundle addition = bundlecontext.installbundle(location);             addition.start();         }     } } 

how can add service located in external jar file , use main jar file used start application?

i've got getting started video explains services , service dynamics. in video see how use bndtools (which highly recommend). registering , consuming services use apache felix dependencymanager.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -