从部署在 tomcat 上的 OSGI equinox 包中进行 JNDI 查找(桥接模式) [英] JNDI lookup from OSGI equinox bundle deployed on tomcat (bridged mode)

查看:103
本文介绍了从部署在 tomcat 上的 OSGI equinox 包中进行 JNDI 查找(桥接模式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 tomcat\context.xml 中配置了我的数据源.我已经部署了Eclipse提供的bridge.war来获取servletbridge环境.

I have my datasource configured in tomcat\context.xml. I have deployed a bridge.war provided by Eclipse to get servletbridge environment.

我开发了另一个包含 servlet 注册代码的 osgi 包,我的目标是使用 JNDI 查找来自这个 servlet 包的数据源.

I have developed another osgi bundle which contains servlet registation code and my aim is to do JNDI look up for datasource from this servlet bundle.

但是我得到

javax.naming.NoInitialContextException:Cannot instantiate class: org.apache.naming.java.javaURLContextFactory (root cause classnotfound for org.apache.naming.java.javaURLContextFactory)

当我在我的 OSGI 包中尝试以下代码时

when I try following code in my OSGI bundle

        Context initContext = new InitialContext();
        Context envContext = (Context) initContext.lookup("java:/comp/env");
        DataSource ds = (DataSource) envContext.lookup("jdbc/TestDB");

我已经在我的 osgi 容器中添加了 catalina.jar 并且作为我的 osgi 包中的一个依赖项.

I have added catalina.jar in my osgi container an also as a dependency in my osgi bundle.

我的bridge.war的launch.ini如下所示:

My launch.ini of bridge.war looks like this:

osgi.*=@null
org.osgi.*=@null
eclipse.*=@null

osgi.parentClassloader=ext
osgi.contextClassLoaderParent=ext
org.osgi.framework.system.packages.extra=org.apache.naming.java

有人可以帮我吗?

推荐答案

嵌入式 OSGi 容器的父级是 ext:Java 扩展类加载器

The parent of the embedded OSGi container is ext: The Java extension class loader

为了能够看到Tomcat的类,必须将launch.ini中的父类加载器更改为fwk:OSGi框架类加载器.

To be able to see the classes of Tomcat, the parent classloader must be changed in launch.ini to fwk: The OSGi framework class loader.

通过这样做,嵌入式 OSGi 容器的父类加载器成为 Web 应用程序的类加载器.如果嵌入式 OSGi 容器中的包想要直接使用来自 webapp 或 Tomcat 的类,您可能需要使用 org.osgi.system.packages.extra 设置列出类的包.

By doing that, the parent classloader of the embedded OSGi container be the classloader of the web application. If a bundle in the embedded OSGi container wants to use a class from the webapp or Tomcat directly, you might have to list the package of the class with org.osgi.system.packages.extra setting.

有关嵌入式 Equinox 的父类加载器的更多信息:http://wiki.eclipse.org/FAQ_How_do_I_add_a_theclass_plug-in_to-in%3F

More information about parent classloaders of embedded Equinox: http://wiki.eclipse.org/FAQ_How_do_I_add_a_library_to_the_classpath_of_a_plug-in%3F

关于Tomcat的类加载器层次结构的更多信息:http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

More information about the class loader hierarchy of Tomcat: http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

这篇关于从部署在 tomcat 上的 OSGI equinox 包中进行 JNDI 查找(桥接模式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆