【问题标题】:java.lang.ClassCastException: Cannot cast org.glassfish.web.loader.WebappClassLoader to org.osgi.framework.BundleReferencejava.lang.ClassCastException:无法将 org.glassfish.web.loader.WebappClassLoader 转换为 org.osgi.framework.BundleReference
【发布时间】:2012-01-12 11:24:18
【问题描述】:

我正在使用 Glassfish 和 OSGI 开发一个简单的应用程序。我找到了这个教程: http://blogs.oracle.com/arungupta/entry/totd_154_dynamic_osgi_services 我修改了这个例子。您可以找到我的自定义示例文件: http://uploading.com/files/cf1ffd63/test.zip/ 我用 web 模块和 EJB 模块创建了 EAR 包。我创建了一个调用 OSGI 包的会话 bean。我成功编译了项目。问题是,当我将包上传到 Glassfish 应用程序服务器并尝试将简单的小程序打开到 Web 模块中时,会出现此错误消息:

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: Cannot cast org.glassfish.web.loader.WebappClassLoader to org.osgi.framework.BundleReference

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.1 logs.
GlassFish Server Open Source Edition 3.1.1

也许问题是缺少依赖。我找不到问题?您知道可能是什么问题吗?

【问题讨论】:

标签: java netbeans glassfish osgi


【解决方案1】:

OSGi Core 4.2 规范 (org.osgi.framework;version=1.5) 的第 3.8.9 节要求所有捆绑类加载器都必须实现 BundleReference 接口。也许 GlassFish 中的类加载器不这样做?您的 GlassFish 版本支持哪个版本的 OSGi Core 规范?

【讨论】:

    【解决方案2】:

    您不应该将应用程序部署为 ear,这两个模块必须作为 OSGi 包单独部署

    【讨论】:

    • 问题是我正在开发一个使用 JNI 的应用程序。据我所知,只有 EAR 包可以包含资源适配器以建立 java->C 桥。是否可以开发可以调用 JNI 的 WAR 存档?
    • 您的资源适配器也可以部署为一个模块,可能是非 osgi 的。
    • 事实证明,EAR 包在设计上不能调用 OSGI 包中的方法。如果有人想要,他可以在这里投票:java.net/jira/browse/GLASSFISH-6741
    【解决方案3】:

    如果我理解正确的话,OSGI 的版本就是问题所在。在 web 模块中,我声明了这一点:

            <dependency>
                <groupId>org.glassfish</groupId>
                <artifactId>osgi-cdi-api</artifactId>
                <version>3.1-SNAPSHOT</version>
                <type>jar</type>
            </dependency> 
    

    我需要添加其他内容吗?

    附言 我使用 Glassfish 3.1.1 - 最新版本。这是已安装组件的列表:

     Source         Button to include column Source in sort.
    felix           OSGi Service Platform Release 4     3.0.8-0     999KB   stable.glassfish.org
    glassfish-appclient     Application Servers     3.1.1-12    1MB     stable.glassfish.org
    glassfish-cluster   Application Servers     3.1.1-12    1MB     stable.glassfish.org
    glassfish-cmp       Application Servers     3.1.1-12    2MB     stable.glassfish.org
    glassfish-common    Application Servers     3.1.1-12    10MB    stable.glassfish.org
    glassfish-common-full   Application Servers     3.1.1-12    210KB   stable.glassfish.org
    glassfish-corba     Application Servers     3.1.0-30    2MB     stable.glassfish.org
    glassfish-corba-base    Application Servers     3.1.0-30    794KB   stable.glassfish.org
    glassfish-ejb       Application Servers     3.1.1-12    298KB   stable.glassfish.org
    glassfish-ejb-lite  Application Servers     3.1.1-12    942KB   stable.glassfish.org
    glassfish-full-incorporation    Application Servers     3.1.1-12    37KB    stable.glassfish.org
    glassfish-full-profile  Application Servers     3.1.1-12    37KB    stable.glassfish.org
    glassfish-grizzly   Application Servers     1.9.36-1    1007KB  stable.glassfish.org
    glassfish-grizzly-full  Application Servers     1.9.36-1    163KB   stable.glassfish.org
    glassfish-gui       Application Servers     3.1.1-12    8MB     stable.glassfish.org
    glassfish-ha        Application Servers     3.1.1-12    53KB    stable.glassfish.org
    glassfish-hk2       Application Servers     3.1.1-12    1MB     stable.glassfish.org
    glassfish-javahelp  Application Servers     2.0.2-1     586KB   stable.glassfish.org
    glassfish-jca       Application Servers     3.1.1-12    1MB     stable.glassfish.org
    glassfish-jcdi      Application Servers     3.1.1-12    2MB     stable.glassfish.org
    glassfish-jdbc      Application Servers     3.1.1-12    922KB   stable.glassfish.org
    glassfish-jms       Application Servers     3.1.1-12    4MB     stable.glassfish.org
    glassfish-jpa       Application Servers     3.1.1-12    5MB     stable.glassfish.org
    glassfish-jsf       Application Servers     2.1.3-4     2MB     stable.glassfish.org
    glassfish-jta       Application Servers     3.1.1-12    110KB   stable.glassfish.org
    glassfish-jts       Application Servers     3.1.1-12    424KB   stable.glassfish.org
    glassfish-management    Application Servers     3.1.1-12    334KB   stable.glassfish.org
    glassfish-nucleus   Application Servers     3.1.1-12    3MB     stable.glassfish.org
    glassfish-osgi-feature-pack     Application Servers     3.1.1-12    37KB    contrib.glassfish.org
    glassfish-osgi-gui  Application Servers     3.1.1-12    656KB   contrib.glassfish.org
    glassfish-osgi-http     Application Servers     3.1.1-12    66KB    stable.glassfish.org
    glassfish-osgi-incorporation    Application Servers     3.1.1-12    37KB    contrib.glassfish.org
    glassfish-registration  Application Servers     3.1.1-12    135KB   stable.glassfish.org
    glassfish-upgrade   Application Servers     3.1.1-12    139KB   stable.glassfish.org
    glassfish-web       Application Servers     3.1.1-12    3MB     stable.glassfish.org
    glassfish-web-incorporation     Application Servers     3.1.1-12    37KB    stable.glassfish.org
    glassfish-web-profile   Application Servers     3.1.1-12    37KB    stable.glassfish.org
    javadb-client       Databases and Tools     10.6.2.1-1  527KB   stable.glassfish.org
    javadb-common       Databases and Tools     10.6.2.1-1  60KB    stable.glassfish.org
    javadb-core         Databases and Tools     10.6.2.1-1  4MB     stable.glassfish.org
    jersey          Web Services    1.9-1.18    2MB     stable.glassfish.org
    metro           Web Services    2.1.1-9     16MB    stable.glassfish.org
    mq-bin-exe      Message-Oriented Middleware     4.5.1-3.2   297KB   stable.glassfish.org
    mq-bin-sh       Message-Oriented Middleware     4.5.1-3.2   85KB    stable.glassfish.org
    mq-config-gf        Message-Oriented Middleware     4.5.1-3.2   60KB    stable.glassfish.org
    mq-core         Message-Oriented Middleware     4.5.1-3.2   4MB     stable.glassfish.org
    mq-server       Message-Oriented Middleware     4.5.1-3.2   6MB     stable.glassfish.org
    pkg             System Tools    1.122.2-54.2834     6MB     stable.glassfish.org
    pkg-java        System Tools    1.122-54.2834   652KB   stable.glassfish.org
    pkg-toolkit-incorporation   System Tools    2.3.4-54.2834   0KB     stable.glassfish.org
    python2.4-minimal   System Tools    2.4.4.0-54.2834     6MB     stable.glassfish.org
    shoal           Application Servers     1.5.34-0    536KB   stable.glassfish.org
    updatetool      System Tools    2.3.4-54.2834   4MB     stable.glassfish.org
    wxpython2.8-minimal     System Tools    2.8.10.1-54.2834    24MB    stable.glassfish.org
    

    【讨论】:

    • 有谁能帮助我吗?我在这个问题上苦苦挣扎了两个多星期。请帮帮我。
    猜你喜欢
    • 2017-07-07
    • 2016-12-05
    • 1970-01-01
    • 2014-07-08
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多