OSGi——运行工具箱的配置(org.eclipse.equinox.http org.eclipse.equinox.servlet.api)问题

前一段时间跟着老师在做有关OSGi的项目。刚从老师口中听到这个技术就两眼冒金星,感觉这就是一个高大上的技术,拿以前自己做的项目和这个一比真的是小巫见大巫。刚开始的时候信心满满,觉得一个月的时间学习加做东西足够了,可真做的时候就发现老师说的是对的,这门技术的学习曲线还是挺陡峭的。

由于刚刚找到工作,老师布置完任务后几天就去公司实习了,想着一边实习一边做OSGi,幸亏进了项目组,整个项目在我来之前已经搭建好了,逻辑也写的差不多了,我一刚刚迈出校园的大学生啥也不会,也就没让我干活(最后回学校答辩的前一天,算是在公司的第20天,这期间就让我干了一个活,修改数据库中一个表的字段名称)。所以我有充裕的时间来学习OSGi,但因为开始对自己的能力高估,并且低估了OSGi的学习难度,所以刚进公司那会问师兄公司里用啥框架,就自己学了一部分ibatis。

总体来说就是前期时间很充裕,没有好好学OSGi,后期时间紧的要命。因为当时学的时候看的是《OSGi与Equinox 创建高度模块化的Java系统》这本书。怎么说呢,这是一本好书,但是因为翻译等原因,这本书上好多概念性的东西,我都看不到脑子里去,有很多的知识都是连蒙带猜滚过的,总之我觉得入门这本书看起来挺费劲的。但因为项目中就是做书上的例子,所以只能硬着头皮看下去,这期间遇到好多问题,都是和老师还有HT一起解决的,瞬间觉得HT的学习能力超强,对整个项目把控很到位,有很多问题都是问他才解决的。

答辩的前几天我提前回到学校,和HT、SY一起再拼命做项目,写报告。为此大学最后一门课设答辩前一天我们三人通宵在教室完成。

还有好多事情就不多说了,在查找资料的期间,看到网上推荐了几本书《OSGi原理与最佳实践(完整版)》、《OSGI实战》、《OSGI-Equinox》因为一直在看《OSGi与Equinox 创建高度模块化的Java系统》,所以忽略这些书。在答辩完回公司的火车上,我觉得OSGi是一个开始,我已经喜欢上这个模块化的东西了,所以还想进一步的去了解并应用它,于是就开始看《OSGI实战》。看到前几章我就发现这真的是一本很好书,每个知识点和注意点都讲解的很清楚,以前一些模糊的地方看到这本书之后也就很清晰了。


---------------------------------------------------------------------------华丽丽的分界线-------------------------------------------------------------------------------------------------------------------------------------------


书上第六章   基于OSGI框架(Equinox)的实战    中第二节 配置工具,按着作者的讲述来进行操作时,出现了错误。首先看一下我的JDK版本


看一下我的eclipse版本号


可能和作者的有区别,所以出现了错误


有以下几个错误

1.作者说引入:org.eclipse.equinox.http org.eclipse.equinox.servlet.api,因为eclipse中没有这两个bundle,所以需要下载,但是他给的网址因为时间问题链接已经失效了,根据错误提示,我就从Google了org.eclipse.equinox.http_1.0.0.v20060601a.jar这个内容,出现了如下内容:


选择第一个搜索结果后打开的是 http://archive.eclipse.org/eclipse/equinox/drops/R-3.2-200606291905/index.php 的是这个地址

如图:


选择下载这个bundle,并放到eclipse目录下的plugins文件夹下。此时如果你在run configuration中寻找这两个bundle,也是找不到的,千万不要忘了重启eclipse。

重启之后再运行,本来以为会万事ok了,其实不然,你会发现还是不行,会看到如下错误:



那就按着报错再引入这个缺失的bundle试试吧


这次总行了吧,好事多磨,还是有错,千万不要急,考验程序猿的时候到了,认真读错误提示:

或许会找到这个提示:

!SESSION 2015-01-12 11:34:21.427 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Command-line arguments:  -dev file:D:/workspaces/.metadata/.plugins/org.eclipse.pde.core/New_configuration/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -console

!ENTRY org.eclipse.equinox.console 4 0 2015-01-12 11:34:23.174
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.console_1.0.100.v20130429-0953 [23]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.service.command; version="0.8.0"
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

!ENTRY org.eclipse.osgi 4 0 2015-01-12 11:34:23.190
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.console_1.0.100.v20130429-0953.jar was not resolved.

!ENTRY org.eclipse.osgi 4 0 2015-01-12 11:34:23.205
!MESSAGE Could not start bundle: org.eclipse.equinox.console
!STACK 0
org.osgi.framework.BundleException: Could not start bundle: org.eclipse.equinox.console
	at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:217)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:298)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.console_1.0.100.v20130429-0953 [23]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.service.command; version="0.8.0"
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
	at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:215)
	... 10 more
Root exception:
org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.console_1.0.100.v20130429-0953 [23]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.felix.service.command; version="0.8.0"
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
	at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:215)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:298)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

如果你按着错误提示查找

org.apache.felix.service.command
这个bundle应该是找不到的,那就删除几个试试,把service.command删除,你会发现这个


把org.apache.felix.gogo.command  org.qpache.felix.gogo.runtime  org.apache.felix.gogo.shell这个三个bundle勾上,再运行试试吧。

这次没有错了。

什么?

你的还有错?

别急,再看看错误提示

!SESSION 2015-01-12 11:36:18.695 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Command-line arguments:  -dev file:D:/workspaces/.metadata/.plugins/org.eclipse.pde.core/New_configuration/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -console

!ENTRY org.eclipse.equinox.http 4 0 2015-01-12 11:36:20.574
!MESSAGE Port 80 is use
!STACK 0
java.net.BindException: Address already in use: JVM_Bind
	at java.net.DualStackPlainSocketImpl.bind0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
	at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
	at java.net.PlainSocketImpl.bind(Unknown Source)
	at java.net.ServerSocket.bind(Unknown Source)
	at java.net.ServerSocket.<init>(Unknown Source)
	at org.eclipse.equinox.http.HttpServerSocket.<init>(HttpServerSocket.java:48)
	at org.eclipse.equinox.http.HttpConfiguration.createServerSocket(HttpConfiguration.java:220)
	at org.eclipse.equinox.http.HttpListener.setProperties(HttpListener.java:108)
	at org.eclipse.equinox.http.HttpListener.<init>(HttpListener.java:55)
	at org.eclipse.equinox.http.HttpConfiguration.createDefaultListeners(HttpConfiguration.java:138)
	at org.eclipse.equinox.http.HttpConfiguration.initialize(HttpConfiguration.java:102)
	at org.eclipse.equinox.http.HttpConfiguration.<init>(HttpConfiguration.java:90)
	at org.eclipse.equinox.http.Http.start(Http.java:70)
	at org.eclipse.equinox.http.Activator.start(Activator.java:33)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

!ENTRY org.eclipse.equinox.http 4 0 2015-01-12 11:36:20.590
!MESSAGE An unexpected IOException occurred
!STACK 0
java.net.BindException: Address already in use: JVM_Bind
	at java.net.DualStackPlainSocketImpl.bind0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
	at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
	at java.net.PlainSocketImpl.bind(Unknown Source)
	at java.net.ServerSocket.bind(Unknown Source)
	at java.net.ServerSocket.<init>(Unknown Source)
	at org.eclipse.equinox.http.HttpServerSocket.<init>(HttpServerSocket.java:48)
	at org.eclipse.equinox.http.HttpConfiguration.createServerSocket(HttpConfiguration.java:220)
	at org.eclipse.equinox.http.HttpListener.setProperties(HttpListener.java:108)
	at org.eclipse.equinox.http.HttpListener.<init>(HttpListener.java:55)
	at org.eclipse.equinox.http.HttpConfiguration.createDefaultListeners(HttpConfiguration.java:138)
	at org.eclipse.equinox.http.HttpConfiguration.initialize(HttpConfiguration.java:102)
	at org.eclipse.equinox.http.HttpConfiguration.<init>(HttpConfiguration.java:90)
	at org.eclipse.equinox.http.Http.start(Http.java:70)
	at org.eclipse.equinox.http.Activator.start(Activator.java:33)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

!ENTRY org.eclipse.equinox.http 4 0 2015-01-12 11:36:20.606
!MESSAGE An unexpected RuntimeException occurred
!STACK 0
java.net.BindException: Address already in use: JVM_Bind
	at java.net.DualStackPlainSocketImpl.bind0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
	at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
	at java.net.PlainSocketImpl.bind(Unknown Source)
	at java.net.ServerSocket.bind(Unknown Source)
	at java.net.ServerSocket.<init>(Unknown Source)
	at org.eclipse.equinox.http.HttpServerSocket.<init>(HttpServerSocket.java:48)
	at org.eclipse.equinox.http.HttpConfiguration.createServerSocket(HttpConfiguration.java:220)
	at org.eclipse.equinox.http.HttpListener.setProperties(HttpListener.java:108)
	at org.eclipse.equinox.http.HttpListener.<init>(HttpListener.java:55)
	at org.eclipse.equinox.http.HttpConfiguration.createDefaultListeners(HttpConfiguration.java:138)
	at org.eclipse.equinox.http.HttpConfiguration.initialize(HttpConfiguration.java:102)
	at org.eclipse.equinox.http.HttpConfiguration.<init>(HttpConfiguration.java:90)
	at org.eclipse.equinox.http.Http.start(Http.java:70)
	at org.eclipse.equinox.http.Activator.start(Activator.java:33)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
osgi> 

看到这句话

!MESSAGE Port 80 is use
你就放心啦,这就是在提示你,默认使用的80端口被占用了,那就改端口号吧。

如图:


怎么改呢,还是在刚才的run configuration下,有个 Arguments标签栏,在VM arguments: 中加入下面这段话

-Dorg.osgi.service.http.port=8080

这是啥意思呢,就是在http服务器的端口号改成了8080端口,如果还被占用,那就再改其他的,但是端口号是有取值范围的

一般用到的是1到65535,其中0不使用
一般的应用程序使用1024到4999用来通讯
5000以后的用来用户自定义端口

遵循这个约定就可以随便取了。

运行没有错误之后,输入ss之后会发现此时正在运行的bundle:

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.9.1.v20140110-1610
4	ACTIVE      org.eclipse.osgi.services_3.3.100.v20130513-1956
18	ACTIVE      org.eclipse.equinox.http_1.0.0.v20060601a
19	ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060601
23	ACTIVE      org.eclipse.equinox.console_1.0.100.v20130429-0953
24	ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215
25	ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036
26	ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605

至此就结束了,

如果您又出现了其他的啥错误,那请您可以留言分享你遇到的错误,咱们共同来解决问题


</pre><pre name="code" class="html">

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值