java - Cannot start embeded Apache Felix -
i want create java desktop application based on apache felix framework. created main java class:
package test.main; import test.activator.activator; import java.util.serviceloader; import java.util.hashmap; import java.util.map; 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 startapplication { private static framework m_framework = null; public static map<integer, string> map = new hashmap<integer, string>(); /** * 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) { map.put(1, "/opt/bundle1.jar"); // map.put(2, "test value 2"); // map.put(3, "test value 3"); // 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(); 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() throws bundleexception, exception { bundlecontext bundlecontext = m_framework.getbundlecontext(); activator hostactivator = new activator(); hostactivator.start(bundlecontext); (string location : map.values()) { bundle addition = bundlecontext.installbundle(location); addition.start(); } } }
when run jar file error:
[rcbandit@laptop target]$ java -jar ./dx-57-1.0.jar welcome launcher ====================== exception in thread "main" java.lang.noclassdeffounderror: org/osgi/framework/launch/frameworkfactory @ dx57.main.startapplication.createframework(startapplication.java:95) @ dx57.main.startapplication.main(startapplication.java:71) caused by: java.lang.classnotfoundexception: org.osgi.framework.launch.frameworkfactory @ java.net.urlclassloader$1.run(urlclassloader.java:217) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:205) @ java.lang.classloader.loadclass(classloader.java:321) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:294) @ java.lang.classloader.loadclass(classloader.java:266) ... 2 more
can tell me how can solve problem?
you need have osgi framework on application classpath, e.g. felix. example should launch follows:
java -cp dx-57-1.0.jar;org.apache.felix.framework-4.2.1.jar test.main.startapplication
Comments
Post a Comment