OSGI 번들이 설치 및 시작되었지만 출력이 표시되지 않음 (OSGI Bundle Installed and Started but no visible output)


문제 설명

OSGI 번들이 설치 및 시작되었지만 출력이 표시되지 않음 (OSGI Bundle Installed and Started but no visible output)

OSGI를 배우려고 합니다. (주로 번들의 동적 로드 및 언로드).

OSGi 포함 방법, 클래스 경로에 The Equinox OSGi 프레임워크 구현을 추가하고 게임을 시작했습니다.

코드는 다음과 같습니다.

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
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.Constants;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;


public class BundleManager {

    /**
     * @param args
     * @throws Exception 
     */
    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();



        BundleContext context = framework.getBundleContext();
        List<Bundle> installedBundles = new LinkedList<Bundle>();

        installedBundles.add(context.installBundle(
                              "file:C:/Users/student/Documents/eclipse/myPlugins/HellowService.jar"));


        for (Bundle bundle : installedBundles) {

       if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null)
                 bundle.start();

         }


        System.out.println("done!!");



    }

}

예 , 효과가있다. 오류가 전혀 없습니다. 그러나 경로:C:/Users/student/Documents/eclipse/myPlugins/HelloService.jar에 jar 파일인 내가 설치한 번들은 시작 메소드에 "HelloWorld"를 포함합니다. 내 Eclipse 콘솔에 "HelloWold"가 표시되지 않습니다. 내가 왜 번들이 시작되었지만 해당 메시지가 표시되지 않습니까? 간단한 도움에 감사드립니다.

참고: HelloService.jar는 내가 이전에 만든 플러그인 프로젝트로, 시작 부분에 "HelloWorld" 메시지를 추가하기 위해 해당 클래스 중 하나에 BundleActivator를 구현했습니다. 메소드를 만들고 마지막으로 C:/Users/student/Documents/eclipse/myPlugins/

디렉토리에 jar 파일로 내보냈습니다.

편집: 여기 내가 설치하고 시작하는 번들의 Activator 클래스:

package com.javaworld.sample.service.impl;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import com.javaworld.sample.service.HelloService;

public class HelloServiceActivator implements BundleActivator {

    ServiceRegistration helloServiceRegistration;


        public void start(BundleContext context) throws Exception {

            HelloServiceFactory helloServiceFactory = new HelloServiceFactory();
            helloServiceRegistration =context.registerService(HelloService.class.getName(), helloServiceFactory, null);

            System.out.println("Hello World!");
        }
        public void stop(BundleContext context) throws Exception {
            helloServiceRegistration.unregister();
        }


}

여기에 번들의 MANIFEST.MF 파일이 있습니다.

Manifest‑Version: 1.0
Bundle‑ManifestVersion: 2
Bundle‑Name: HelloService
Bundle‑SymbolicName: com.javaworld.sample.HelloService
Bundle‑Version: 1.0.0.qualifier
Bundle‑Activator: com.javaworld.sample.service.impl.HelloServiceActivator
Bundle‑Vendor: JAVAWORLD
Bundle‑RequiredExecutionEnvironment: JavaSE‑1.7
Import‑Package: org.osgi.framework;version="1.3.0"
Export‑Package: com.javaworld.sample.service

번들을 내보내는 방법은 다음을 마우스 오른쪽 버튼으로 클릭하는 것입니다. 번들 프로젝트‑>내보내기‑>실행 가능한 Jar 파일‑> 그런 다음 Launch Configuration을 BundleManager(번들을 설치하는 클래스임)로 선택합니다.

여전히 "Hello World!"가 표시되지 않습니다. 내 애플리케이션에서 번들을 시작할 때 메시지가 표시됩니다.


참조 솔루션

방법 1:

Your launcher does not wait for the OSGi Framework to stop. I would expect this program to start everything but then immediately shut down, because we reach the end of the main method. Refer back to my tutorial where I show how to use the Framework.waitForStop method.

Having said that, I would expect the output from your HelloWorld bundle to actually appear before the shutdown. So it seems likely there is an error in that bundle also. Perhaps you haven't declared the activator? I can only guess, because you haven't given any details.

방법 2:

It turned out that I was exporting the bundle incorrectly. That's because I tried to do it by myself. Here's how the bundle should be exported as a jar file:

   Open the plugin export wizard File > Export... > Plug‑in Development >
   Deployable plug‑ins and fragments . 
   Then select the bundle you want to export and the destination directory. Done!

You can now use the path of the jar file to install the bundle. In my case, it is:

 installedBundles.add(context.installBundle(
                              "file:C:/Users/student/Documents/eclipse/myPlugins/plugins/com.javaworld.sample.HelloService_1.0.0.201307220322.jar"));

Source: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Fexport_wizards%2Fexport_plugins.htm

And for sure thanks to @Neil Bartlett

(by Traveling SalesmanNeil BartlettTraveling Salesman)

참조 문서

  1. OSGI Bundle Installed and Started but no visible output (CC BY‑SA 2.5/3.0/4.0)

#equinox #osgi-bundle #osgi #frameworks






관련 질문

Eclipse에서 OSGi 래퍼 번들을 실행할 수 없습니다. .jar은 잘 빌드되고 있지만 파일을 대상/클래스에 복사하려면 어떻게 해야 합니까? (Can't run OSGi wrapper bundle in Eclipse; .jar is building okay, but how do I also copy files into target/classes?)

최대 절전 모드 5.0 + 춘분 4.5.0 및 사용자 정의 UserType (hibernate 5.0 + equinox 4.5.0 and custom UserType)

Domino에 OSGi 서블릿 배치(IBM 프리젠테이션) - 404 오류 (Deploying OSGi Servlet to Domino (IBM presentation) - 404 error)

Java 7을 사용하여 Equinox 3.8.2 프로젝트 컴파일 (Compile Equinox 3.8.2 Project with java 7)

OSGI 애플리케이션에서 EntityManager를 제공하는 모범 사례 (Best practice to provide EntityManager in OSGI applications)

Eclipse RCP 제품 파일 - 플랫폼별 종속성이 있는 여러 플랫폼을 처리하는 방법 (Eclipse RCP Product File - how to handle multiple platforms with platform specific dependencies)

OSGI 번들이 설치 및 시작되었지만 출력이 표시되지 않음 (OSGI Bundle Installed and Started but no visible output)

Jetty 서버의 포트(Equinox OSGi) (Port in Jetty server (Equinox OSGi ))

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

OSGi 가져오기 버전 제한을 동적으로 설정하시겠습니까? (Setting OSGi import version restrictions dynamically?)

OSGI의 AspectJ LoadTimeWeaving (AspectJ LoadTimeWeaving on OSGI)

user.home 디렉토리에 쓰지 못하도록 Eclipse 위치를 어떻게 수정합니까? (How modify Eclipse locations to prevent write to user.home directory?)







코멘트