install [URL]
|
将URL表示的bundle安装到框架中
|
uninstall [bundleID]
|
将id=bundleID的bundle卸载
|
start [bundleID]
|
启动一个bundle
|
stop [bundleID]
|
停止一个bundle
|
refresh [bundleID]
|
刷新bundle
|
update [bundleID]
|
更新bundle 的内容
|
ss
|
简单显示所有bundle的状态
|
status
|
展示安装的bundle和注册的服务
|
headers [bundleID]
|
展示bundle 的manifest中的元数据
|
1
2
3
4
|
package
org.serc.helloworld;
public
interface
Hello {
void
sayHello();
}
|
1
2
3
4
5
6
7
8
9
10
|
package
org.serc.helloworld.impl;
public
class
HelloImpl
implements
Hello{
final
String helloString;
public
HelloImpl(String helloString){
this
.helloString= helloString;
}
public
void
sayHello(){
System.out.println(
this
.helloString);
}
}
|
1
|
Export-Package: org.serc.helloworld;version=
"1.0"
|
1
2
3
4
5
6
7
8
9
10
11
12
|
package
org.serc.helloworld.activator;
public
class
Activator
implements
BundleActivator {
private
List
new
ArrayList
public
void
start(BundleContext ctx) {
registrations.add(ctx.registerService(Hello.
class
.getName(),
new
HelloImpl(
"Hello, OSGi"
),
null
));
}
public
void
stop(BundleContext ctx) {
for
(ServiceRegistration registration : registrations) {
System.out.println(
"unregistering:"
+ registration);
registration.unregister();
}
}
|
1
|
Bundle-Activator:org.serc.helloworld.activator.Activator
|
1
2
3
4
5
6
|
Bundle-ManifestVersion:
2
Bundle-SymbolicName:org.serc.helloworld
Bundle-Version:
1.0
Bundle-Activator:org.serc.helloworld.activator.Activator
Import-Package:org.osgi.framework
Export-Package: org.serc.helloworld;version=
"1.0"
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package
org.serc.helloworld.client;
public
class
HelloUser
implements
BundleActivator {
public
void
start(BundleContext ctx) {
ServiceReference ref = ctx.getServiceReference(Hello.
class
.getName());
if
(ref !=
null
) {
Hello hello =
null
;
try
{
hello= (Hello) ctx.getService(ref);
if
(hello !=
null
)
hello.sayHello();
else
System.out.println(
"Service:Hello---objectnull"
);
}
catch
(RuntimeException e) {
e.printStackTrace();
}
finally
{
ctx.ungetService(ref);
hello=
null
;
}
}
else
{
System.out.println(
"Service:Hello---notexists"
);
}
}
public
void
stop(BundleContext ctx)
throws
Exception {
}
}
|
1
2
3
4
5
|
Bundle-ManifestVersion:
2
Bundle-SymbolicName:org.serc.helloworld.client
Bundle-Version:
1.0
Bundle-Activator:org.serc.helloworld.client.HelloUser
Import-Package:org.serc.helloworld;version=
"[1.0,2.0)"
,org.osgi.framework
|