OSGI注册资源的两种方式
来源:互联网 发布:非典怎么消失的 知乎 编辑:程序博客网 时间:2024/04/29 10:32
1.通过类
package sample.http;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;
import org.osgi.util.tracker.ServiceTracker;
public class Activator implements BundleActivator {
private ServiceTracker httpServiceTracker;
public void start(BundleContext context) throws Exception {
httpServiceTracker = new HttpServiceTracker(context);
httpServiceTracker.open();
}
public void stop(BundleContext context) throws Exception {
httpServiceTracker.close();
httpServiceTracker = null;
}
private class HttpServiceTracker extends ServiceTracker {
public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
}
public Object addingService(ServiceReference reference) {
HttpService httpService = (HttpService) context.getService(reference);
try {
httpService.registerResources("/helloworld.html", "/helloworld.html", null); //$NON-NLS-1$ //$NON-NLS-2$
httpService.registerServlet("/helloworld", new HelloWorldServlet(), null, null); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
return httpService;
}
public void removedService(ServiceReference reference, Object service) {
HttpService httpService = (HttpService) service;
httpService.unregister("/helloworld.html"); //$NON-NLS-1$
httpService.unregister("/helloworld"); //$NON-NLS-1$
super.removedService(reference, service);
}
}
}
2.通过创建plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension-point id="servlets" name="HttpService servlets" schema="schema/servlets.exsd"/>
<extension-point id="resources" name="HttpService resources" schema="schema/resources.exsd"/>
<extension-point id="httpcontexts" name="HttpService httpcontexts" schema="schema/httpcontexts.exsd"/>
<extension
id="helloServlet"
point="org.eclipse.equinox.http.registry.servlets">
<servlet
alias="/ext/helloworld"
class="sample.http.registry.HelloWorldServlet">
<init-param
name="servlet-name"
value="Test Servlet">
</init-param>
<init-param
name="testParam"
value="test param value">
</init-param>
</servlet>
</extension>
<extension
id="helloResource"
point="org.eclipse.equinox.http.registry.resources">
<resource
alias="/ext/helloworld.html"
base-name="/helloworld.html"
/>
</extension>
</plugin>
- OSGI注册资源的两种方式
- osgi注册服务和servlet的两种方法
- OSGI框架下,bundle的两种启动方式
- Broadcast的两种注册方式
- 数据库注册两种方式的比较
- 注册native函数的两种方式
- 注册广播的两种方式
- Android 广播注册的两种方式
- BroadcastReceiver的两种注册方式
- 安卓中BroadcastReceiver 注册的两种方式
- 广播注册的两种方式
- 广播注册的两种方式
- 注册JNI函数的两种方式
- 广播接收者的两种注册方式
- 注册广播接收者的两种方式
- 注册JNI函数的两种方式
- Android广播的两种注册方式
- 安卓中BroadcastReceiver 注册的两种方式
- UITextView 加载其他View
- The Necklace UVA10054
- 曼哈顿距离 VS 欧氏距离 VS 切比雪夫距离
- 音视频解决方案中的透明通道
- 数据结构(C#)--二叉查找树的先序,中序,后序的遍历问题以及最大值,最小值,插入,删除
- OSGI注册资源的两种方式
- 关于Android发送邮件
- 关于Spring中org.springframework.beans.factory.UnsatisfiedDependencyException异常
- UITextView圆角、背景设置与居中
- iMAC修改本地HOST
- [2月25日的脚本] 如何自动地安装NET4.5, PowerShell 3.0, KB2592525 (PowerShell)
- 笑话 整理
- 音视频解决方案中的缓冲技术
- 控件、UI 半年学习总结下自定义控件用法和一些常用页面效果