OSGI实战中的问题:Exception in org.eclipse.datatools.enablement.oda.ws.ui.Activator.start()
今天在接触OSGI时遇到了一个问题,弄了好久才搞定,特总结,以免大家出现类似情况。
友情提示:要是遇到莫名其妙的问题,最好的解决办法:
1、清空.metadata;
2、重新导工程;
3、一个Bundle一个Bundle的运行,不要一次把所有Bundle都添加进去,如图,先选择一个Bundle,然后Add Required Bundles。
更多的问题解决方法,请见下面转载:
对osgi有了一个初步的了解之后,准备写段代码跑跑,一试身手,
先下载了一份Bluedavy 的《OSGI实战》
里边有可以直接运行的代码,双击run.bat运行正常,暗爽!
开始练习《OSGI实战》中用户登录验证模块,一行一行敲代码,第一个变化就是工程之间相互引用不能在Build path里添加工程引用了,改成了在MANIFEST.MF当中添加Import-Package
在学习过程当中还是遇到了不少问题,记录下来,帮助遇到和我同样样问题的少走弯路。
我用的是eclipse3.4 jdk1.6
1.Import-Package时org.eclipse.equinox.servlet.api这个包死活找不到。
在eclipse3.4已经不存在了直接导入javax.servlet_2.4.0.v200806031604.jar就可以了
如果没有添加javax.servlet会出现 INSTALLED UserValidatorWebBundle_1.0.0
强行启动会抛出以下异常
org.osgi.framework.BundleException: The bundle could not be resolved. Reason: Missing Constraint: Require-Bundle: javax.servlet; bundle-version="2.4.0"
2.如果使用了Equinox OSGI Declarative Service需要下载 eclipse-equinox-SDK-3.4.2.zip
因为Declarative Service实现并没有包含在Eclipse的默认软件包中,需要单独从 Eclipse 的的网站上获得,下载包当中的plugins和features复制到eclipse当中重启
org.eclipse.equinox.ds_1.0.0.v20080427-0830.jar是运行时用到的bundle
org.eclipse.equinox.ds用到了org.eclipse.equinox.util_1.0.0.v20080414.jar
都要在config.ini当中添加并启动
3.一切看似启动正常了,log当中还是有以下异常
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
还得启动 org.eclipse.osgi.util_3.1.300.v20080303.jar 这个bundle
4.如果http://localhost/demo/page/login.htm 这个页面不能访问可能org.eclipse.equinox.http_1.0.200.v20080421-2006.jar没有启动,如何htm能访问了http://localhost/demo/login 不能访问 可能org.eclipse.equinox.http.servlet_1.0.100.v20080427-0830.jar没有启动
总结一下用户登录验证模块要启动的bundle
id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.2.R34x_v20080826-1230
1 ACTIVE ConfigFileValidatorBundle_1.0.0
2 ACTIVE DBValidatorBundle_1.0.0
4 ACTIVE UserValidatorBundle_1.0.0
5 ACTIVE LDAPValidatorBundle_1.0.0
9 ACTIVE UserValidatorWebBundle_1.0.0
10 ACTIVE org.eclipse.equinox.util_1.0.0.v20080414
11 ACTIVE org.eclipse.equinox.ds_1.0.0.v20080427-0830
12 ACTIVE javax.servlet_2.4.0.v200806031604
13 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
14 ACTIVE org.eclipse.equinox.http.servlet_1.0.100.v20080427-0830
15 ACTIVE org.eclipse.equinox.http_1.0.200.v20080421-2006
17 ACTIVE org.eclipse.osgi.util_3.1.300.v20080303
当缺少什么bundle时,自己去网上下就行,然后用导入Plug- ins and Fragments的方式将bundle导入,便可以引用了,所以别当成什么高深的东西,别忘了在运行时用"Add Required Bundles",它帮我们加入会用的的bundles,这个就帮我们很大的忙了.
在第一个例子(源码中的classic)中,用代码注册的方式来注册服务,即在每个实现服务接口的bundle里的Activator注册自己的服务到指定服务名下,如
- package org.riawork.demo.user.validator;
- /*
- * RIAWork.org
- *
- * OSGI Opendoc Demo
- */
- import org.osgi.framework.BundleActivator;
- import org.osgi.framework.BundleContext;
- import org.osgi.framework.ServiceRegistration;
- import org.riawork.demo.service.user.Validator;
- import org.riawork.demo.service.user.impl.ConfigFileValidatorImpl;
- /**
- * desc: ConfigFileBundle Activator,采用传统的方式完成服务的注册
- *
- * @author jerry
- */
- public class Activator implements BundleActivator {
- // --------------------------------------------Instance Variables
- private ServiceRegistration serviceReg=null;
- // --------------------------------------------Public Method
- /* (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- //实现Validator的Bunble都会在Activator里将自己的新的实现注册到Validator.class.getName()名下,这样Validator.class.getName()为名的服务就有多个了
- public void start(BundleContext context) throws Exception {
- serviceReg=context.registerService(Validator.class.getName(), new ConfigFileValidatorImpl(), null);
- }
- /* (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- if(serviceReg!=null)
- serviceReg.unregister();
- }
- }
package org.riawork.demo.user.validator;
/** RIAWork.org* * OSGI Opendoc Demo*/
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.riawork.demo.service.user.Validator;
import org.riawork.demo.service.user.impl.ConfigFileValidatorImpl;
/*** desc: ConfigFileBundle Activator,采用传统的方式完成服务的注册** @author jerry*/
public class Activator implements BundleActivator {// --------------------------------------------Instance Variablesprivate ServiceRegistration serviceReg=null;// --------------------------------------------Public Method/* (non-Javadoc)* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)*///实现Validator的Bunble都会在Activator里将自己的新的实现注册到Validator.class.getName()名下,这样Validator.class.getName()为名的服务就有多个了public void start(BundleContext context) throws Exception {serviceReg=context.registerService(Validator.class.getName(), new ConfigFileValidatorImpl(), null);}/* (non-Javadoc)* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)*/public void stop(BundleContext context) throws Exception {if(serviceReg!=null)serviceReg.unregister();}}
在第二个例子(源码中的ds),采用的是在配置文件里声明的方式来发布一个bundle里的服务的,即在 ConfigFileValidatorBundle,DBValidatorBundle,LDAPValidatorBundle这三个实现 UserValidatorBundle接口的bundle里没有Activator来注册它们的实现服务,而是在MANIFEST.MF配置文件里加入 Service-Component: OSGI-INF/component.xml来发布声明在项目目录下的OSGI-INF/component.xml配置文件的服务。
打包时,按着文档来做是不行的,打包的时候,org.eclipse.osgi的jar包和run.bat是在一个目录里,而在它们目录下再建 configuration目录(存放config.ini文件)和bundles目录(存放自己打包出来的bundle和它们运行依赖的 bundle),还有一点在注意的是拷贝文档里的config.ini内容到config.ini文件是不能运行的,可以是有中文字符在里面。
我这里能运行的如下:
- osgi.noShutdown=true
- # 当前系统下运行的 Bundle,可以在此指定 Bundle 的启动顺序,在后续的
- # StartLevel Service章节中会详细的介绍
- #避免Unable to acquire application service. Ensure that the org.eclipse.core.runtime错误
- eclipse.ignoreApp=true
- #osgi.bundles=reference\:file\:bundles/ConfigFileValidatorBundle_1.0.0.jar@start,reference\:file\:bundles/DBValidatorBundle_1.0.0.jar@start,reference\:file\:bundles/LDAPValidatorBundle_1.0.0.jar@start,reference\:file\:bundles/org.eclipse.equinox.http_1.0.301.R35x_v20090728.jar@start,reference\:file\:bundles/javax.servlet_2.5.0.v200806031605.jar@start,reference\:file\:bundles/org.eclipse.osgi.services_3.2.0.v20090520-1800.jar@start,reference\:file\:bundles/UserValidatorBundle_1.0.0.jar@start, reference\:file\:bundles/UserValidatorWebBundle_1.0.0.jar@start
- osgi.bundles=plugins/ConfigFileValidatorBundle_1.0.0.jar@start,\
- plugins/DBValidatorBundle_1.0.0.jar@start,\
- plugins/LDAPValidatorBundle_1.0.0.jar@start,\
- plugins/org.eclipse.equinox.http_1.0.301.R35x_v20090728.jar@start,\
- plugins/javax.servlet_2.5.0.v200806031605.jar@start,\
- plugins/org.eclipse.osgi.services_3.2.0.v20090520-1800.jar@start,\
- plugins/UserValidatorBundle_1.0.0.jar@start,\
- plugins/UserValidatorWebBundle_1.0.0.jar@start,\
- plugins/org.eclipse.equinox.ds_1.1.1.R35x_v20090806.jar@start,\
- plugins/org.eclipse.equinox.util_1.0.100.v20090520-1800.jar@start
- osgi.bundles.defaultStartLevel=4
osgi.noShutdown=true # 当前系统下运行的 Bundle,可以在此指定 Bundle 的启动顺序,在后续的 # StartLevel Service章节中会详细的介绍 #避免Unable to acquire application service. Ensure that the org.eclipse.core.runtime错误 eclipse.ignoreApp=true#osgi.bundles=reference\:file\:bundles/ConfigFileValidatorBundle_1.0.0.jar@start,reference\:file\:bundles/DBValidatorBundle_1.0.0.jar@start,reference\:file\:bundles/LDAPValidatorBundle_1.0.0.jar@start,reference\:file\:bundles/org.eclipse.equinox.http_1.0.301.R35x_v20090728.jar@start,reference\:file\:bundles/javax.servlet_2.5.0.v200806031605.jar@start,reference\:file\:bundles/org.eclipse.osgi.services_3.2.0.v20090520-1800.jar@start,reference\:file\:bundles/UserValidatorBundle_1.0.0.jar@start, reference\:file\:bundles/UserValidatorWebBundle_1.0.0.jar@start osgi.bundles=plugins/ConfigFileValidatorBundle_1.0.0.jar@start,\plugins/DBValidatorBundle_1.0.0.jar@start,\plugins/LDAPValidatorBundle_1.0.0.jar@start,\plugins/org.eclipse.equinox.http_1.0.301.R35x_v20090728.jar@start,\plugins/javax.servlet_2.5.0.v200806031605.jar@start,\plugins/org.eclipse.osgi.services_3.2.0.v20090520-1800.jar@start,\plugins/UserValidatorBundle_1.0.0.jar@start,\plugins/UserValidatorWebBundle_1.0.0.jar@start,\plugins/org.eclipse.equinox.ds_1.1.1.R35x_v20090806.jar@start,\plugins/org.eclipse.equinox.util_1.0.100.v20090520-1800.jar@startosgi.bundles.defaultStartLevel=4
这里不要忘记加入ds的bundle不然用Service-Component: OSGI-INF/component.xml配置就不起作用了,发布不了服务的,因为是由ds的bundle来扫描发现相应的服务,并加于管理的。
OSGI实战中的问题:Exception in org.eclipse.datatools.enablement.oda.ws.ui.Activator.start()相关推荐
- seata 如何开启tcc事物_如何能在实战中完成分布式事务?知道这些点很重要
在这篇文章中我详细介绍了分布式事务是什么,实现分布式事务有哪些常用的方案,但是其中的东西很多是偏于理论,很多读者对其真正在实战上的使用可能还是有点差距.所以在前几次文章的更新中,我介绍了很多关于Sea ...
- OSGI实战(2)-走近OSGI-开发第一个Plug-in项目
上一次我们介绍了什么是OSGI和OSGI在我们的项目中起到了什么作用.这次我们来亲手使用OSGI技术. 主要利用Eclipse开发工具提供给我们的plug-in插件工程模板来创建我们的工程.零距离的体 ...
- Mybatis-Plus实战中的几个条件构造器Wrapper用法
Mybatis-Plus实战中的几个条件构造器Wrapper用法 其实Wrapper有很多其他的方法,组合起来也是殊途同归,大家可以自己点开源码去查看一些方法的使用说明 @Testvoid conte ...
- JAVA中常见的Exception
这篇文章转载自 : JAVA中常见的Exception 常见的几种如下: NullPointerException - 空指针引用异常 ClassCastException - 类型强制转换异常. I ...
- Java中的异常 Exception
Java中的异常 Exception java.lang.Exception类是Java中所有异常的直接或间接父类.即Exception类是所有异常的根类. 比如程序: public class Ex ...
- mybatis insert 忽略 联合唯一索引_MySQL实战中,Insert语句的使用心得总结
提到MySQL的Insert语句,你肯定不陌生,或许已经张口就来:不就是insert into table values(xxx,xxx,xxx)嘛!没错,但在实战中,根据不同的需求场景,插入操作在语 ...
- OSGi环境中的Servlet基本身份验证
您首先需要获得对OSGI HTTP Service的引用. 您可以通过声明性服务来做到这一点. 这篇文章将集中在获得对HTTP服务的引用之后的步骤. 注意:此职位的完整课程位于此处 通过OSGI HT ...
- sass笔记 - 实战中颜色的玩法总结
sass笔记 - 实战中颜色的玩法总结 这篇文章是针对自己封装UI组件库的读者的,旨在为项目提供通用的颜色方案本文需要读者拥有CSS.SASS/SCSS相关基础知识. jack lee 的 CSDN ...
- Winrm后门在实战中的巧妙应用
winrm后门在实战中的巧妙应用 在权限维持阶段,有很多方法来做权限稳固,但是对于一台服务器来讲,我们可以利用端口复用打造隐蔽winrm后门,从而对机器进行稳定控制. 1.winrm相关介绍 winr ...
最新文章
- mysql日志文件相关的配置【2】
- java程序实现按并发数收费_java-实战java高并发程序设计-ch3JDK并发包
- 2020CCPC(长春) - Ragdoll(启发式合并+带权并查集)
- 深度学习(四十六)Adversarial Autoencoders学习笔记
- 舒服的网页登录界面设计灵感
- 基于express和vue框架的校园商品交易平台 答辩PPT免费下载
- CCF NOI1087 第K名
- EL表达式中fn函数
- 推荐两个非常不错的公众号
- Java 泛型完全解读
- python小游戏之圣诞树
- nfc卡模式与标准模式_马苏开启年后减肥模式,素颜自拍打卡,皮肤光滑香汗淋漓惹人注目...
- Detected problems with app native libraries (please consult log for detail): lib.so: text relocation
- 刘宇凡:从吃饭中的道理领悟SEO
- sql获取字符串长度函数
- 文献阅读: 基因组选择技术在农业动物育种中的应用
- matlab示波器多个接口,simulink在一个图形中画出多个示波器曲线的方法
- 去除String首尾字符
- 为什么signed char的范围是-128~127
- c语言面向对象编程显示,c语言面向对象编程
热门文章
- python实现6的阶乘_python设计一个阶乘函数,并使用该函数求出6的阶乘。(怎么用python求阶乘的和教程)...
- 北京租赁住房用地分布,八张大数据图表让你一目了然!
- 贵州安装杆塔倾斜在线监测装置
- 产品迭代团队协作敏捷流程图
- 运行结果展示 |(DPT)Vision Transformers for Dense Prediction
- 初出茅庐的小李第113篇博客项目笔记之机智云智能浇花器实战(2)-基础Demo实现
- 符号速率,码片速率,业务速率,信道编码,扩频因子(转)
- 软件测试之第三方快捷支付_支付相关测试方法
- JS与JQuery分别实现淘宝(五星好评特效)
- 如何恢复android误删的文件夹,手机里的文件删了怎么恢复?这里有最全面的恢复方法...