2012-01-12 73 views
0

我正在使用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模塊此錯誤消息出現:java.lang.ClassCastException:無法將org.glassfish.web.loader.WebappClassLoader強制轉換爲org.osgi.framework.BundleReference

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 

也許問題是缺少依賴。我找不到問題?你有什麼想法可能是什麼問題?

+0

後從GlassFish日誌完整堆棧跟蹤另行部署。 – 2012-01-12 11:45:47

+0

這是錯誤堆棧http://pastebin.com/FNaTd9jP – 2012-01-12 12:09:08

回答

0

如果我正確理解你的OSGI的版本是問題。在Web模塊中,我已經聲明:

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

我需要添加其他內容嗎?

p.s 我使用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 
+0

有沒有人可以幫助我?我爲這個問題掙扎了兩個多星期。請幫幫我。 – 2012-01-13 08:57:18

1

OSGi Core 4.2規範(org.osgi.framework; version = 1.5)的3.8.9節要求所有bundle類加載器都必須實現BundleReference接口。也許GlassFish中的類加載器不這樣做?您的GlassFish版本支持哪種版本的OSGi Core規範?

1

您shouldn'tdeploy應用程序作爲一個耳朵,兩個模塊都必須爲OSGi包

+0

問題是我正在開發一個使用JNI的應用程序。據我所知,只有EAR包可以包含資源適配器才能使java-> C橋。是否有可能開發可調用JNI的WAR文件? – 2012-01-14 15:30:42

+0

您的資源適配器也可以作爲模塊部署,可能是非osgi模塊。 – pdudits 2012-01-14 20:40:24

+0

事實證明,EAR包不能通過設計從OSGI包中調用方法。這裏如果有人想要他可以爲此投票:http://java.net/jira/browse/GLASSFISH-6741 – 2012-01-15 10:30:51

相關問題