Equinox Server-side(二)
这次讲讲如何将http作为一个bundle,让其他bundle来访问其http.
从Eclipse.org上将以下的包下下来
org.eclipse.equinox.http
OR
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.servlet
org.mortbay.jetty (v5_1_11 - from Orbit Depot)
org.apache.commons.logging (v1_0_4 - from Orbit Depot)
javax.servlet (v2_4 - from Orbit Depot)
[optional] org.eclipse.equinox.http.registry
地址是
http://www.eclipse.org/equinox/server/downloads/equinoxhttp-anon.psf
http://www.eclipse.org/equinox/server/downloads/jettyhttp-anon.psf
上面两个文件是ecplise的小组项目导入文件.
可任选一个导入,下面的是将jetty作为http响应
这个时候就可以写web应用了.
可以先写一个在各种servlet容器能运行的程序,然后把它转化为bundle就可以了
具体做法是
先在plugin.xml中 加入资源的扩展
如下
<plugin>
<extension point="org.eclipse.equinox.http.registry.resources">
<resource
alias="/files"
base-name="/web_files"/>
</extension>
</plugin>
这样http就能访问web_files下的文件了
在加入servlet扩展
<extension point="org.eclipse.equinox.http.registry.servlets">
<servlet
alias="/test"
class="com.example.servlet.MyServlet"/>
</extension>
这样.就能通过/test来访问com.example.servlet.MyServlet这个servlet了
现在Equinox已经支持servlet和jsp
ok,在OSGI框架下run一下这个bundle,然后在浏览器中输入http://localhost/files/index.html
成功
参考:http://www.eclipse.org/equinox/server/http_writing_application.php