포함된 Apache Felix를 시작할 수 없습니다. (Cannot start embeded Apache Felix)


문제 설명

포함된 Apache Felix를 시작할 수 없습니다. (Cannot start embeded Apache Felix)

I want to create Java Desktop application based on Apache Felix Framework. I created this 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;

/**
 * This class provides a static {@code main()} method so that the bundle can be
 * run as a stand‑alone host application. In such a scenario, the application
 * creates its own embedded OSGi framework instance and interacts with the
 * internal extensions to providing drawing functionality. To successfully
 * launch the stand‑alone application, it must be run from this bundle's
 * installation directory using "{@code java ‑jar}". The locations of any
 * additional extensions that have to be started, have to be passed as command
 * line arguments to this method.
 */
public class StartApplication
{

    private static Framework m_framework = null;
    public static Map<Integer, String> map = new HashMap<Integer, String>();

    /**
     * Enables the bundle to run as a stand‑alone application. When this static
     * {@code main()} method is invoked, the application creates its own
     * embedded OSGi framework instance and interacts with the internal
     * extensions to provide drawing functionality. To successfully launch as a
     * stand‑alone application, this method should be invoked from the bundle's
     * installation directory using "{@code java ‑jar}". The location of any
     * extension that shall be installed can be passed as parameters.
     * <p>
     * For example if you build the bundles inside your workspace, maven will
     * create a target directory in every project. To start the application from
     * within your IDE you 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 The locations of additional bundles to 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 be null if the application is run from the command
        // line.
        // Check it anyway.
        //String[] locations = args != null ? args : new String[0];

        // Print welcome banner.
        System.out.println("\nWelcome to My 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 for creating an embedded Framework. Tries to create a
     * {@link FrameworkFactory} which is then be used to create the framework.
     *
     * @param config the configuration to create the framework with
     * @return a Framework with the given configuration
     */
    private static Framework createFramework(Map<String, String> config)
    {
        ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader
                .load(FrameworkFactory.class);
        for (FrameworkFactory factory : factoryLoader)
        {
            return factory.newFramework(config);
        }
        throw new IllegalStateException(
                "Unable to load FrameworkFactory service.");
    }

    /**
     * Installs and starts all bundles used by the application. Therefore the
     * host bundle will be started. The locations of extensions for the host
     * bundle can be passed in as parameters.
     *
     * @param bundleLocations the locations where extension for the host bundle
     * are located. Must not be {@code null}!
     * @throws BundleException if something went wrong while installing or
     * starting the bundles.
     */
    private static void installAndStartBundles() throws BundleException, Exception
    {
        BundleContext bundleContext = m_framework.getBundleContext();
        Activator hostActivator = new Activator();
        hostActivator.start(bundleContext);

        for (String location : map.values())
        {
            Bundle addition = bundleContext.installBundle(location);
            addition.start();
        }
    }
}

When I run the jar file I get this error:

[rcbandit@Laptop target]$ java ‑jar ./DX‑57‑1.0.jar

Welcome to My Launcher
======================

Exception in thread "main" java.lang.NoClassDefFoundError: org/osgi/framework/launch/FrameworkFactory
    at dx57.main.StartApplication.createFramework(StartApplication.java:95)
    at dx57.main.StartApplication.main(StartApplication.java:71)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.launch.FrameworkFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    ... 2 more

Can you tell me how I can solve this problem?


참조 솔루션

방법 1:

You need to have an OSGi Framework on the application classpath, e.g. Felix. For example you should launch as follows:

java ‑cp DX‑57‑1.0.jar;org.apache.felix.framework‑4.2.1.jar test.main.StartApplication

(by Peter PenzovNeil Bartlett)

참조 문서

  1. Cannot start embeded Apache Felix (CC BY‑SA 3.0/4.0)

#apache-felix #osgi #java






관련 질문

Apache Felix 웹 콘솔 브랜딩 (Branding Apache Felix web console)

포함된 Apache Felix를 시작할 수 없습니다. (Cannot start embeded Apache Felix)

Glassfish OSGI 웹 콘솔 자격 증명 (Glassfish OSGI Webconsole Credentials)

Android에 OSGi Felix 포함 (Embed OSGi Felix in Android)

Amdatu OSGI 이벤트 처리기 다른 수신기가 수신 대기 중일 때 수신 대기 시간 지연 (Amdatu OSGI Event Handler time delay to listen when other listener are listening)

OSGi 번들이 Felix 호스트 응용 프로그램으로 시작되지 않음 (OSGi Bundle not starting with Felix Host application)

임베디드 osgi 프레임워크, 서비스 기능을 호출하는 방법은 무엇입니까? (Embedded osgi framework, how to call service functions?)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

OSGI(Apache Felix)에서 다른 사람의 번들에 대해 AOP를 구현하는 방법은 무엇입니까? (How to implement AOP for someone else's bundles in OSGI (Apache Felix)?)

OSGi r4.1의 ServiceTracker (ServiceTracker in OSGi r4.1)

번들 OSGI를 업데이트하는 동안 서비스/구성 요소를 계속 실행하는 방법 (How to keep service/componnet running while update bundle OSGI)

Equinox에서 Arquillian 실행 (Running Arquillian in Equinox)







코멘트