[ OSGi ] 1 - OSGi 기초 에서 OSGi platform 까지 구동했다.
여기서는 OSGi안에서 서비스될 plugin( bundle ) 을 만들어 보도록 하자.
우선 eclipse를 구동후 프로젝트를 생성하자
프로젝트 생성
1. 프로젝트 생성에서 Plug-in Project를 선택한다.
2. This plug-in is targeted to run with 에서 "an OSGi framework" 을 선택하고 "standrd"를 선택한다.
3. ID를 입력한다.
ID : plugin(bundle)의 식별자가 된다. (OSGi command 에서 ss 명령어 입력시 나오는 Bundle-SymbolicName )
Version : plugin(bundle) 버전
Name : Bundle-Name
Activator : plugin 시작시 실행되는 java class
MANIFEST.MF 확인
프로젝트 생성시 입력한 정보들이 MANIFEST.MF에 반영이 되었는지 확인한다.
참고로 MANIFEST.MF 제일 마직막줄에는 밑에 빨간 박스처럼 한줄이 추가로 들어가야 bug 없이 잘 동작 한다.
|
Activator.java 확인
자동으로 생성된 Activator.java의 start method에 System.out.println("start hello osgi world");
stop method에 System.out.println("stop hello osgi world");를 입력 한다.
Plugin 배포
1. 프로젝트에서 오른쪽 마우스 클릭후 Export...를 선택한다.
|
2. Deployable plug-ins and fragments를 선택한다.
3. 배포할 경로를 선택한다.
아래와 같이 sample을 선택하면 sample/plugins 밑으로 자동으로 들어간다.
4. 최종적으로 폴더는 다음과 같은 구조로 된다.
sample |-- plugins |-- org.apache.felix.gogo.command_xxx.jar |-- org.apache.felix.gogo.runtime_xxx.jar |-- org.apache.felix.gogo.shell_xxx.jar |-- org.eclipse.equinox.common_xxx.jar |-- org.eclipse.equinox.console_xxx.jar |-- org.eclipse.osgi_xxx.jar |-- sample.HelloWorldOSGi_1.0.0.jar |-- configuration |-- config.ini |
Plug-in Install
1. OSGi를 실행 시킨다.
C:\develop\OSGi\sample\plugins>java -Declipse.ignoreApp=true -jar org.eclipse.osgi_3.10.0.v20140606-1445.jar -console -consoleLog osgi> |
2. ss 명령어를 입력하면 다음과 같이 나온다
osgi> ss "Framework is launched." id State Bundle 0 ACTIVE org.eclipse.osgi_3.10.0.v20140606-1445 1 ACTIVE org.eclipse.equinox.common_3.6.200.v20130402-1505 2 ACTIVE org.eclipse.equinox.console_1.1.0.v20140131-1639 3 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605 4 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215 5 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036 osgi> |
3. plug-in install 명령어를 입력한 후 ss 명령어를 다시 입력하면
sample.HelloWorldOSGi.jar가 install 된 것을 확인 할수 있다.
osgi> install file:sample.HelloWorldOSGi_1.0.0.jar Bundle id is 6 Location file:sample.HelloWorldOSGi_1.0.0.jar State 2 Bundle 6|Installed | 1|sample.HelloWorldOSGi (1.0.0) Version 1.0.0 LastModified 1408447306585 Headers Bundle-Activator = kr.co.jabsiri.helloworldosgi.Activator Bundle-ManifestVersion = 2 Bundle-Name = HelloWorldOSGi Bundle-RequiredExecutionEnvironment = JavaSE-1.6 Bundle-SymbolicName = sample.HelloWorldOSGi Bundle-Version = 1.0.0 Import-Package = org.osgi.framework;version="1.3.0" Manifest-Version = 1.0 BundleContext null BundleId 6 SymbolicName sample.HelloWorldOSGi RegisteredServices null ServicesInUse null Module osgi.identity; osgi.identity="sample.HelloWorldOSGi"; type= "osgi.bundle"; version:Version="1.0.0" [id=6] osgi> ss "Framework is launched." id State Bundle 0 ACTIVE org.eclipse.osgi_3.10.0.v20140606-1445 1 ACTIVE org.eclipse.equinox.common_3.6.200.v20130402-1505 2 ACTIVE org.eclipse.equinox.console_1.1.0.v20140131-1639 3 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605 4 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215 5 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036 6 INSTALLED sample.HelloWorldOSGi_1.0.0 osgi> |
** plugins folder 밑의 파일은 full path를 입력하지 않지만, plugins folder 외부에 있는 파일은 full path를 입력해준다.
( 예: install file:C:\sample.HelloWorldOSGi_1.0.0.jar )
4. plugin을 start 시키기 위해 start 명령어를 입력한다.
osgi> start 6 start hello osgi world osgi> ss "Framework is launched." id State Bundle 0 ACTIVE org.eclipse.osgi_3.10.0.v20140606-1445 1 ACTIVE org.eclipse.equinox.common_3.6.200.v20130402-1505 2 ACTIVE org.eclipse.equinox.console_1.1.0.v20140131-1639 3 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605 4 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215 5 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036 6 ACTIVE sample.HelloWorldOSGi_1.0.0 |
start 되면서 Activator.java의 start method에 입력한 "start hello osgi world" 출력된 것을 확인 할 수 있다.
ss 명령어 입력시 State도 "ACTIVE"로 변경된 것을 볼수 있다.
4. plugin을 stop 시키기 위해 stop 명령어를 입력한다.
osgi> stop 6 stop hello osgi world osgi> ss "Framework is launched." id State Bundle 0 ACTIVE org.eclipse.osgi_3.10.0.v20140606-1445 1 ACTIVE org.eclipse.equinox.common_3.6.200.v20130402-1505 2 ACTIVE org.eclipse.equinox.console_1.1.0.v20140131-1639 3 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605 4 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215 5 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036 6 RESOLVED sample.HelloWorldOSGi_1.0.0 osgi> |
stop 되면서 Activator.java의 stop method에 입력한 "stop hello osgi world" 출력된 것을 확인 할 수 있다.
ss 명령어 입력시 State도 "RESOLVED"로 변경된 것을 볼수 있다.
첨부 1 : HelloWorldOSGi plugin Eclipse Project
첨부 2 : OSGi Framework
참고 자료
[1] Guru's Blog OSGi 시작하기 http://xguru.net/page/2?s=osgi |
'JAVA' 카테고리의 다른 글
[ OSGi ] 6 - Spring DM 3 (0) | 2014.08.28 |
---|---|
[ OSGi ] 5 - Spring DM 2 (0) | 2014.08.26 |
[ OSGi ] 4 - Spring DM 1 (0) | 2014.08.25 |
[ OSGi ] 3 - OSGi plugin 의존 관계 (0) | 2014.08.20 |
[ OSGi ] 1 - OSGi 기초 (0) | 2014.06.24 |