Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Modeler   Code  
»áÔ±   
 
   
 
 
     
   
 ¶©ÔÄ
  ¾èÖú
GlassFish OSGi-JavaEE (Ò»): GlassFishÓëÆóÒµ¼¶OSGi¿ª·¢
 
×÷Õß ÌÀÓ¾£¬»ðÁú¹ûÈí¼þ    ·¢²¼ÓÚ 2014-09-03
  3953  次浏览      27
 

ǰÑÔ

»¶Ó­½øÈëGlassFish OSGi-JavaEEרÌ⣡×Ô´ÓGlassFish v3¿ªÊ¼£¬Ò»¸öеÄÌØÐÔ±»¼ÓÈëµ½GlassFishÖУ¬ÄǾÍÊÇGlassFish OSGi-JavaEE¡£±¾×¨Ì⽫·ÖΪ¾Å¸ö²¿·ÖÏò´ó¼Ò½éÉÜGlassFish OSGi-Java EEÏà¹ØµÄ֪ʶ£º

Part1:¶ÔGlassFish OSGi-JavaEE×ö¼òµ¥µÄ½éÉܲ¢¼òÒªÐðÊöÆóÒµ¼¶µÄOSGi¿ª·¢µÄÏÖ×´¡£

Part2:Àí½âGlassFish OSGi/WEBÈÝÆ÷²¢¿ª·¢ºÍ²¿ÊðÒ»¸öWEB Ó¦ÓóÌÐòBundleµ½GlassFishÖС£

Part3:Àí½âGlassFish OSGi/EJBÈÝÆ÷²¢¿ª·¢ºÍ²¿ÊðÒ»¸öEJB Ó¦ÓóÌÐòBundleµ½GlassFishÖС£

Part4:Àí½âGlassFish OSGi/CDI(ÉÏÏÂÎÄÒÀÀµ×¢Èë)¹æ·¶ÒÔ¼°GlassFish OSGi/CDIµÄʵÏÖ£¬Í¬Ê±£¬Õ¹Ê¾ÈçºÎʹÓÃGlassFish OSGi/CDIÀ´¼ò»¯ÆóÒµ¼¶OSGiµÄ¿ª·¢¡£

Part5,Part6:¼¯³ÉEARºÍOSGi£¬ÆäÖУ¬Part5»áͨ¹ý¼¯³ÉApache Aries ApplicationÌØÐÔÀ´Óµ±§EARºÍOSGi£»Part6»áͨ¹ýÒ»¸öÕæÊµµÄ°¸ÀýÀ´Õ¹Ê¾ÈçºÎʹÓÃEJB BundleÀ´ÇŽÓEARºÍOSGiÒÔ´ïµ½ÏàͬµÄÄ¿µÄ¡£

Part7:ÉîÈë½â¶ÁGlassFish¡¢HK2ºÍOSGiÈýÕߵĹØÏµ, ͬʱ£¬¶ÔÓÚÉçÇø¾­³£Ìáµ½µÄÎÊÌâ²ûÊöÒ»¸ö×Ô¼ºµÄ¹Ûµã¡£(¡°HK2ÔÚδÀ´½«»áDeadÂ𣿡±)

Part8:ÉîÈëÀí½âGlassFishÄÚºË(Ä£¿éµÄÅäÖᢼÓÔØÒÔ¼°Æô¶¯)£¬Í¬Ê±£¬ÒÔÒ»¸ö°¸ÀýչʾÈçºÎÀ©Õ¹GlassFishÀ´¼ÓÈë¸ü¶à×Ô¶¨ÒåÄ£¿é¡£

Part9:¹±Ï×GlassFish OSGiÒÔ¼°OSGi-JavaEEµÄÁ÷³Ì¡£

±¾×¨Ì⽫¼Ù¶¨¶ÁÕßÓµÓÐGlassFishºÍOSGiµÄ»ù±¾ÖªÊ¶£¬ÏÞÓÚÆª·ùÔ­Òò£¬ÎÒ½«²»»áרÃŽéÉÜGlassFishºÍOSGiµÄ»ù±¾ÖªÊ¶¡£Èç¹û¶ÁÕ߸ոսӴ¥GlassFish£¬½¨Òé´ó¼Ò²Î¿¼ÒÔÏÂÁ´½Ó:

Èç¹û¶ÁÕß²¢²»Á˽âOSGi£¬ÍƼö´ó¼ÒÔĶÁÒÔϵÄÊé¼®:

Neil Bartlett¡¯s ¡°OSGi in Practice¡±

Richard S. HallµÈ ¡°OSGi In Action¡±

Èç¹ûÓÃÒ»¾ä»°À´¶¨Ò塱ʲôÊÇ GlassFish OSGi-JavaEE¡±µÄ»°£¬ÄÇôÎÒÃÇ¿ÉÒÔÕâÑù˵£º

GlassFish OSGi-JavaEE¾ÍÊÇÆóÒµ¼¶OSGiµÄGlassFishʵÏÖ¡£

´Ó2005ÄêGlassFish 1.0µ½ÏÖÔÚ4.0µÄ·¢²¼£¬GlassFishÒѾ­×ß¹ýÁË9¸öÄêÍ·£¬ÔÚÕâ9ÄêÖУ¬GlassFish¾­ÀúÁËJavaEE5µ½JavaEE7µÄ½ø»¯£¬¾­ÀúÁËSun±»OracleµÄÊÕ¹º£¬¾­ÀúÁ˼ܹ¹ÉϵÄÖØ´ó±ä¸ü¡­¡­ÔÚÎÒ¿´À´£¬×îÎªÖØÒªµÄ¸Ä±äÊÇGlassFish 3.0µÄÄں˺ÍÉè¼ÆÀíÄîµÄÖØ´ó±ä¸ü£¬ÉõÖÁ˵ÊÇÒ»´Î¸ïÃü£¡ 3.0֮ǰ£¬GlassFishÊÇÒ»¸ö²»¿É·Ö¸î»òÕß˵ÊÇÒ»¸öÕûÌ廯(monolithic)µÄÅÓÈ»´óÎÄÚºËÓë×é¼þÒÔ¼°¸÷¸ö×é¼þÖ®¼ä½ôñîºÏ£¬È±·¦×ã¹»Áé»îµÄÀ©Õ¹ÐÔ£¬Æô¶¯ÐÔÄܲ»¸ß¡£3.0ʱ´ú£¬Çé¿ö·¢ÉúÁ˸ù±¾ÐÔµÄת±ä£¬ÄÚºËÒÀÍÐHK2ºÍOSGi£¬¸÷¸öÄ£¿éÍêÈ«²ÉÓÃOSGiÉè¼ÆÀíÄGlassFish±äµÃ¸ü¼ÓÇáÁ¿¼¶ºÍÄ£¿é»¯£¬ÄÚºËÓë×é¼þÒÔ¼°¸÷¸ö×é¼þÖ®¼äʵÏÖÁËËÉñîºÏ£¬ÓÐןü¼ÓÁ¼ºÃµÄ¿ÉÀ©Õ¹ÐÔ£¬Æô¶¯ÐÔÄÜÓÐÁËÖʵÄÌá¸ß£¬¸üÎªÖØÒªµÄÊÇ´ó´óÌá¸ßÁË¿Éά»¤ÐÔ¡£Í¬Ê±£¬¸ü¶àÓÐÌØµãµÄÄ£¿é³öÏÖÁË£¬ GlassFish OSGi-JavaEE¾ÍÊÇÆäÖÐÖ®Ò»¡£¶øÕâÒ»Çж¼Òª¹é¹¦ÓÚOSGi!

ÁíÒ»·½Ã棬 ·ÅÑÛµ±Ç°ÊÀ½çÉÏÆäËûÖ÷Á÷µÄ¿ªÔ´JavaEEÓ¦Ó÷þÎñÆ÷£¬ÈçJBOSS 7(ÏÖÔÚÒѾ­¸üÃûΪWildfly), Apache Geronimo 3µÈ¾ù²ÉÓÃÄ£¿é»¯µÄÉè¼ÆÀíÄ¾¡¹ÜJBOSS 7ûÓÐÖ±½Ó²ÉÓÃOSGi×÷ΪÄںˣ©£¬Á¦Í¼Ê¹Ó¦Ó÷þÎñÆ÷ÊÝÉí£¬¸ü¼Ó¾ßÓпÉά»¤ÐԺͿÉÀ©Õ¹ÐÔ¡£

ÎÒÃÇÒѾ­¿´µ½Ä£¿é»¯µÄÉè¼ÆÀíÄîÔÚJavaEEÓ¦Ó÷þÎñÆ÷ÁìÓò´ó»ñ³É¹¦£¬OSGi×÷Ϊģ¿é»¯Éè¼ÆÀíÄîÖÐ×î¾ß´ú±íÐԵIJúÎ¹¦²»¿Éû£¡

±¾×¨Ìâ²¢²»×¨Ã޲ÊöOSGiµÄ»ù±¾ÖªÊ¶ÒÔ¼°ÈçºÎ²ÉÓÃOSGiÀ´Éè¼ÆJavaEEÓ¦Ó÷þÎñÆ÷£¬Ïà·´£¬ÎÒÃÇ̽ÌÖÈçºÎʹÓÃOSGiÀ´¿ª·¢ÆóÒµ¼¶JavaÓ¦Óᣵ«ÊÇ£¬µ±Ìáµ½OSGiÓëÆóÒµ¼¶Javaʱ£¬ÎÒÃÇÊÆ±Ø½«»áÅ׳öÒ»¸öÎÊÌ⣺ΪʲôÆóÒµ¼¶JavaÐèҪʹÓÃOSGi?

ΪÁ˻شðÕâ¸öÎÊÌ⣬ÎÒÃÇÐèÒª½øÒ»²½½â´ðÒÔϵÄÁ½¸öÖØÒªµÄÎÊÌâ:

ÆóÒµ¼¶Java¿ª·¢ÓÐÄÄЩ²»×㣿

½èÖúOSGiÄܹ»½â¾öÕâЩ²»×ãÂð£¿

ÆóÒµ¼¶Java¿ª·¢ÓÐÄÄЩ²»×ã

ÆóÒµ¼¶JavaÊÇÓɹ¹½¨ÔÚºËÐÄJavaÉϵÄһϵÁп⡢APIÒÔ¼°¿ò¼ÜËÉÉ¢¹¹³ÉµÄ£¬²¢ÇÒÕâЩ¿â¡¢APIÒÔ¼°¿ò¼ÜΪ¿ª·¢ÈËÔ±ÌṩÁËһϵÁÐµÄÆóÒµ·þÎñ£¬ÀýÈ磬·Ö²¼Ê½×é¼þ¿ª·¢¡¢ÊÂÎñ¡¢³Ö¾Ã»¯·ÃÎÊÊý¾Ý¿âµÈ¡£ÆóÒµ¼¶JavaÒѾ­È¡µÃÁ˾޴óµÄ³É¹¦£¨ÎÞÂÛÊÇ JavaEE ±¾Éí»¹ÊÇ Spring ¿ò¼Ü£©£¬µ«ÊÇ£¬Ëæ×ÅÆóÒµ¼¶JavaÓ¦ÓóÌÐòµÄ¹æÄ£ºÍ¸´ÔӶȵIJ»¶ÏÔö¼Ó£¬ÕâЩӦÓóÌÐòÒѾ­¿ªÊ¼±äµÃ¸ü¼ÓµÃ±¿ÖغÍÅӴ󣬱ê×¼JavaµÄһЩ¹ÌÓеÄÎÊÌâÒ²Ô½·¢±äµÃÑÏÖØ£¬ÓÐʱÉõÖÁÊÇÖÂÃüµÄ¡£

classpathµØÓü

ÖÚËùÖÜÖ®£¬±ê×¼JavaµÄclasspathÊÇ±âÆ½(flat)µÄ½á¹¹£¬Ò²¾ÍÊÇ˵£¬ÊÇÒÔÏßÐÔ˳ÐòÔÚÖ¸¶¨µÄclasspathÖÐËÑË÷Àà¡£ÀýÈ磬ͼ1ÖУ¬

ͼ1: ±ê×¼JavaÖÐ±âÆ½(flat)µÄclasspath½á¹¹

ÀàAÓÐÁ½¸ö²»Í¬µÄ°æ±¾£¬·ÅÔÚÁ½¸ö²»Í¬µÄJARÖУ¬¶ÔÓÚijЩ±»²¿ÊðµÄÓ¦ÓóÌÐòÀ´Ëµ£¬Ò²ÐíËüÃÇÏëҪʹÓð汾1µÄÀàA,¶ÔÓÚÁíһЩ±»²¿ÊðµÄÓ¦ÓóÌÐòÀ´Ëµ£¬Ò²ÐíËüÃÇÏ£ÍûʹÓð汾2µÄÀàA¡£µ«ÊÇ£¬±âƽµÄclasspath½á¹¹¾ö¶¨Á˺ÜÓпÉÄܲ»»á¼ÓÔØ°æ±¾2µÄÀàA£¬ÒòΪ°æ±¾1µÄÀàA½«Ê×Ïȱ»·¢ÏֺͼÓÔØ¡£

¶ÔÓÚСµÄ³ÌÐò£¬Ò²ÐíÎÒÃÇÄܹ»Ñ¸ËÙ·¢ÏÖÕâ¸öÎÊÌâ²¢ÇÒͨ¹ýµ÷Õûjar°üÔÚclasspathÖеÄ˳ÐòÀ´½â¾ö¡£µ«ÊÇ£¬µ±Ó¦ÓóÌÐòµÄ¹æÄ£ºÍ¸´ÔÓÐÔÈÕÒæÉý¼¶Ê±£¬Õâ¸öÓ¦ÓóÌÐòµÄclasspath¿ÉÄܷdz£µÄ´ó(Óɼ¸Ê®¸öÉõÖÁ¼¸°Ù¸öJAR¹¹³É)£¬ËÑË÷classpath»¨µÄʱ¼äÒ²»áºÜ´ó£¬Ò»µ©¶ªÊ§ÁËÏ£Íû¼ÓÔØµÄij¸öÀàµÄ»°£¬ºÜÄÑÔÚ¶Ìʱ¼äÄÚ±»·¢ÏÖ¡£ÒÔϵÄһЩ³¡¾°½øÒ»²½ÃèÊöÁËÕâ¸öÎÊÌâ¡£

classpathÖÐȱʧÁËÔËÐÐʱµÄÒÀÀµ

Ò²ÐíÒòΪijÖÖÔ­Òò£¬µ±Ó¦ÓóÌÐòÔËÐÐʱ£¬µ±Ç°Ó¦ÓóÌÐòµÄclasspathÖÐȱʧÁËij¸öÒÀÀµ¡£ÄÇô£¬ÔÚ×îºÃµÄÇéÐÎÏ£¬Äܹ»ÔÚÔËÐеÄÔçÆÚͨ¹ýÅ׳öClassNotFoundExceptionÒì³£·¢ÏÖÕâÑùµÄȱʧ¡£µ«ÊÇ£¬ÔÚ×îÔã¸âµÄÇéÐÎÏ£¬ÔËÐеÄÔçÆÚ²»»á·¢ÏÖȱʧµÄÒÀÀµ£¨ÒòΪûÓÐÔËÐе½Ïà¹ØµÄÂß¼­£©£¬Ö±µ½Êý¸öÐÇÆÚ£¨ÉõÖÁ¼¸Ä֮꣩ºó£¬Í¨¹ýÅ׳öµÄClassNotFoundExceptÒì³£²ÅÄÜ·¢ÏÖÕâÑùµÄȱʧ£¬µ«ÊÇ£¬ÐÞ²¹µÄ³É±¾¿ÉÄÜ»áºÜ´ó£¬Èç¹ûÄã²»¹»×ßÔ˵ϰ£¬ÕâÑùµÄÒ»¸öÒÀÀµÈ±Ê§ºÜ¿ÉÄܻᵼÖÂÒ»¸öÒѾ­ÔËÐÐÁ˺ܳ¤Ê±¼äµÄ¹Ø¼üÈÎÎñ(Mission-Critical)³ÌÐò£¨Èç¹ÉƱ½»Ò×£¬´óÐÍÔÚÏß¹ºÎïµÈ£©Í»È»±ÀÀ££¬¶øÄãÈ´ÊøÊÖÎ޲ߡ£

classpathÖеİ汾³åÍ»

Ò²ÐíÓÐÒ»ÖÖ·½Ê½Äܹ»»Ø±Ü¡°ÒÀÀµÍ»È»È±Ê§¡±µÄÎÊÌ⣬¼´°ü×°(wrap)ËùÓеÄÒÀÀµµ½Õâ¸öÓ¦ÓóÌÐòÖ®ÖÐ(ÀýÈç:¶ÔÓÚWARÀ´Ëµ£¬ÎÒÃǽ«ÒÀÀµ·ÅÖõ½µ½WEB-INF/libÖÐ)¡£ÎÒÃÇÔÝÇÒ²»¿¼ÂÇЧÂÊÎÊÌ⣬ÒòΪ¶ÔÓÚÿ¸öÓ¦ÓóÌÐò¶¼Óõ½µÄһЩ¹²Í¨µÄÒÀÀµ£¬°ü×°Ò»·Ý¿½±´ÊÇÒ»ÖÖ×ÊÔ´µÄÈßÓ࣬¹Ø¼üÊÇÕâÖÖ°ü×°µÄ·½Ê½Î´±ØÄܹ»Ê¹Ó¦ÓóÌÐòÕýÈ·µØÔËÐС£ÏëÏóÒ»ÏÂÕâÑùÒ»ÖÖ³¡¾°:Èç¹ûÔËÐÐÔÚͬһ¸öJVMµÄ¶à¸öÓ¦ÓóÌÐò¹«ÓÃijһÏîÒÀÀµµÄ»°£¬»áÊÇʲôÑùµÄ½á¹ûÄØ£¿

°´ÕÕÕâÖÖ°ü×°µÄ·½Ê½£¬Õâ¸ö¹«ÓõÄÒÀÀµ½«»á±»Ã¿¸öÓ¦ÓóÌÐò¶¼°ü×°Ò»·Ý¿½±´£¬µ±ÆäÖÐÒ»¸ö¿½±´Ê×ÏȳöÏÖÔÚclasspathÖв¢ÇÒ±»¼ÓÔØÊ±,ÆäËûµÄ¿½±´½«±»ºöÂÔ¡£ÄÇô£¬Èç¹ûÕâ¸ö¹«ÓÃÒÀÀµµÄ°æ±¾Ò»Ö£¬²»»áÓÐʲôÎÊÌâ¡£µ«ÊÇ£¬µ±°æ±¾²»Ò»ÖÂʱ£¬Ò»Ð©Ó¦ÓóÌÐò½«»áÔËÐÐÕý³££¬µ«ÊÇÁíһЩӦÓóÌÐòºÜ¿ÉÄÜ×îÖÕ»á³öÏÖ¡± NoSuchMethodError¡±£¬ÒòΪËüÃÇËùµ÷Óõķ½·¨¸ù±¾²»´æÔÚ(ËüÃÇËùÏ£ÍûÒÀÀµµÄ°æ±¾±»ÆäËû°æ±¾ÆÁ±ÎÁË)¡£ÔÚһЩ¸üÔã¸âµÄÇéÐÎÏ£¬Ã»ÓÐÏÔʽµÄÒì³£»ò´íÎóÅ׳ö£¬³ÌÐò¿´ÆðÀ´Ò²ÔÚÕý³£µØÔËÐУ¬µ«ÊÇÔËÐеÄÐÐΪÊÇ´íÎóµÄ£¬Õâ²¢²»ÈÝÒ×±»·¢ÏÖ¡£

ÈÃÎÒÃÇ´ÓJavaEEµÄÊÓ½ÇÔÙ¿´Ò»ÏÂÕâÑùµÄ°ü×°·½Ê½£¬ÔÚÒ»¸öJavaEE»·¾³ÖУ¬Ã¿¸öʵÀý(ÀýÈç: GlassFishµÄInstance)¶¼¿ÉÄÜפÁô¶à¸öÓ¦ÓóÌÐò£¬ÎªÁ˽â¾ö¡°ÒÀÀµÍ»È»È±Ê§¡±µÄÎÊÌ⣬ JavaEE¹æ·¶½¨Òé°üװÿ¸öÓ¦ÓóÌÐòµÄÒÀÀµµ½¸ÃÓ¦ÓóÌÐòÖ®ÖУ¬¿´ÆðÀ´ÕâÊÇÒ»¸öÀíÏëµÄ½â¾ö·½°¸£¬µ«ÊÇ£¬Çé¿ö¿ÉÄܸü¼ÓµÃÔã¸â£¬ÒòΪJavaEEÓ¦Ó÷þÎñÆ÷±¾Éí¾Í¿ÉÄÜÒÀÀµÁ˺ܶ࿪ԴµÄ¿â£¬¶øÓ¦ÓóÌÐòÒ²¿ÉÄÜÒÀÀµÁËÏàͬµÄÕâЩ¿â¡£ÕâÑùµÄ»°£¬¼´±ãËùÓеÄÓ¦ÓóÌÐò¶¼Ê¹ÓÃÁËÏàͬ°æ±¾µÄ¿â£¬µ«ÒòΪJavaEEÓ¦Ó÷þÎñÆ÷ʹÓÃÁ˲»Í¬°æ±¾µÄ¿â£¬¾ÍºÜ¿ÉÄܵ¼ÖÂÕâЩӦÓóÌÐòÔËÐÐÒì³££¬µ«ÊÇ£¬ÕâÑùµÄÎÊÌâͨ³£ºÜÄÑ·¢ÏÖÒ²ºÜÄѵ÷ÊÔ¡£

¸´ÔÓÈÃÊÂÇé¿´ÆðÀ´¸üÔã¸â

Ó¦ÓóÌÐòÔÚÈÕÒæ±äµÃ¸´ÔÓ£¬ÎÊÌâÒ²ÔÚ²»¶ÏµØ·¢Éú¡£BBC NewsÐÂÎÅÕ¾µãÉϵÄһƪÎÄÕÂ[1]Ìáµ½:

The core of the problem is that the business software used by the institutions has become horrifically complex, according to Lev Lesokhin, strategy chief at New York-based software analysis firm Cast.

He says developers are good at building new functions, but bad at ensuring nothing goes wrong when the new software is added to the existing mix.

¡°Modern computer systems are so complicated you would need to perform more tests than there are stars in the sky to be 100% sure there were no problems in the system,¡± he explains.

¼òµ¥µØËµ£¬2012ÄêÒøÐÐϵͳÖз¢ÏÖÁËÐí¶àÑÏÖØµÄÎÊÌ⣬ÕâЩÎÊÌâµ¼ÖÂÁËÖ§¸¶´¦ÀíÖеÄËðʧºÍÆäËûÎÊÌâ¡£ÕâÆªÎÄÕÂÔ¤²âÁ˵±Ó¦ÓóÌÐò±äµÃ¸´ÔÓʱ£¬ÕâÑùµÄËðʧ½«»áÔÚδÀ´±äµÃ¸üΪÆÕ±é¡£

¾Í¸´ÔÓÐÔ¶øÑÔ£¬ÓÐÁ½²ãµÄº¬Òå:

a. Ó¦ÓóÌÐòµÄÂß¼­±äµÃ¸üΪ¸´ÔÓ

b. Ó¦ÓóÌÐòµÄ½á¹¹±äµÃ¸üΪ¸´ÔÓ£¬Ä£¿é¸üΪÅÓ´ó

ÎÞÂÛÊÇa»¹ÊÇb£¬ÕâÑùµÄÓ¦ÓóÌÐòÓкܶ඼ÊÇÓÉñîºÏÐԺܸߵĴúÂë¹¹³ÉµÄ£¬ÓÃHolly CumminsºÍTimothy Ward[2]µÄ»°À´Ëµ£¬ÕâЩ¶¼ÊÇ»ìÂÒ(spaghetti)µÄ´úÂë¡£ÏÂͼÑÝʾÁËÒ»¸ö¾ßÓлìÂÒ´úÂë¹¹³ÉµÄÓ¦ÓóÌÐò:

ͼ2: Ò»¸ö´øÓкÜÉٽṹ»¯µÄ²¢ÇҸ߶ÈÏ໥¹ØÁªµÄ»ìÂÒµÄÓ¦ÓóÌÐò¡£ÊµÏß´ú±í׿ÈÊDZàÒëÆÚµÄÒÀÀµÒ²ÊÇÔËÐÐÆÚµÄÒÀÀµ£¬¶øÐéÏß½ö½ö´ú±íÔËÐÐÆÚµÄÒÀÀµ¡£

´Óͼ2ÖУ¬²»ÄÑ·¢ÏÖ£¬¶ÔÓÚÿ¸ö¶ÔÏ󣬺ÜÄÑ׼ȷµØ·¢ÏÖËüµÄÿһ¸öÒÀÀµÒÔ¼°´«µÝÐÔÒÀÀµ£¬¸ü²»ÒªËµ·¢ÏÖÕâЩÒÀÀµµÄ°æ±¾ÁË¡£ºÜ¿ÉÄÜÔÚij¸öÀàÖУ¬ÓкܶàµÄÒÀÀµ(ÕâЩÒÀÀµ°üÀ¨ÁËÏÔʽµÄÒÀÀµ£¬Ò²°üÀ¨ÁËÐí¶àÒþʽµÄÒÀÀµ)£¬¶ÔÓÚС¹æÄ£µÄÓ¦ÓóÌÐòÀ´Ëµ£¬Äã¿ÉÄܺÜÈÝÒ׵ط¢ÏÖÕâЩÒÀÀµ£¬µ«ÊÇ£¬¶ÔÓÚÒ»¸ö¸´ÔÓÐԺܸߵÄÓ¦ÓóÌÐòÀ´Ëµ£¬´úÂëºÜÅÓ´óÒ²ºÜÄѶÁ£¬ÄÇô£¬ÏëÒªÇåÎúµØÊ¶±ðÒÀÀµ²¢²»ÈÝÒס£

¶ÔÓÚÕâЩ¾ßÓлìÂÒ´úÂëµÄ¹¤³Ì£¬µ±Î´À´ÊÔÍ¼Ìæ»»Ò»¸öÒÀÀµµÄ°æ±¾Ê±£¬ºÜÓпÉÄÜÔì³É³ÌÐòÔËÐв»ÕýÈ·£¬¸üÑÏÖØµØ£¬µ¼Ö³ÌÐòÔËÐбÀÀ£¡£ÁíÍ⣬µ±ÊÔͼΪ³ÌÐòÔö¼ÓÒ»¸öÐµĹ¦ÄÜʱ£¬ÒòΪ²»ÄÜÇåÎúµØ°ÑÎÕ³ÌÐòµÄÿ¸ö²¿·ÖµÄÒÀÀµ¹ØÏµ£¬Ö»ÄܼÄÏ£ÍûÓÚ×ö¸ü¶àµÄ²âÊÔ£¬¶øÕâЩ²âÊÔÖÐÒ²ÐíÓÐһЩ¸ù±¾Ã»ÓбØÒª£¬Èç¹ûÄã´ò¸öíïÏëÉÙ²âÊÔһЩ£¬ÄÇô¾ÍÓпÉÄÜÕÐÖÂеÄÎÊÌ⣬ÕâÒ²¾ÍÏñBBC NewsµÄÄÇÆªÎÄÕÂËù·´Ó³µÄÄÇÑù¡£

½øÒ»²½À´Ëµ£¬³öÏÖ»ìÂÒ´úÂëµÄ¸ù±¾Ô­ÒòÆäʵ¾ÍÊÇJAR±¾Éíȱ·¦ÏÔʽµÄÒÀÀµËµÃ÷¡£Ò»¸ö¸´ÔӵįóÒµÓ¦ÓÿÉÄÜÓɶà¸öJAR¹¹³É£¬»òÕßËü±¾Éí¾Í»á±»´ò°ü³ÉÒ»¸öJAR£¬ÕâЩJAR²»½öÒÀÀµ±ê×¼Java¿â»¹ÒÀÀµÁËÆäËûµÄһЩJAR¡£Òò´Ë£¬Èç¹ûÒª²¿ÊðÕâÑùµÄÆóÒµÓ¦Óõϰ£¬±ØÐëÒ²Òª²¿ÊðËüÒÀÀµµÄÆäËûJAR¡£ÀýÈç:Apache JCloudsÒÀÀµGoogle GuiceºÍGoogle GuavaµÈ£¬Èç¹ûʹÓÃJCloudsµÄÓ¦ÓóÌÐòµÄclasspathÖ®ÖÐûÓÐGuiceºÍGuavaµÄ»°£¬ÄÇôÕâ¸öÓ¦ÓóÌÐò½«²»¿ÉÄÜÕý³£¹¤×÷¡£

µ«ÊÇ£¬ÎÒÃÇÈçºÎÖªµÀÕâЩÒÀÀµºÍ´«µÝÒÀÀµÄØ£¿Èç¹ûApache JCloudsÓкܺõÄÎĵµËµÃ÷£¬ÁоÙÁËÕâЩÒÀÀµ£¬ÄÇôÕâ²»»áÓÐʲôÎÊÌ⣬µ±È»£¬Èç¹ûÄãÊÇÒ»¸öMavenר¼ÒµÄ»°£¬Í¨¹ýApache JCloudsµÄ¹¤³ÌPomÎļþ£¬ÄãÒ²ÄÜʶ±ð³öÕâЩÒÀÀµ¡£µ«ÊÇ£¬Ðí¶à¿â²¢Ã»ÓкܺõÄÎĵµËµÃ÷£¬¶øÇÒÄã¿ÉÄÜÒ²²»ÊÇMavenר¼Ò»òÕßÕâЩ¿â¸ù±¾¾Í²»ÊÇÓÃMavenÕâЩºÃµÄÒÀÀµ¹¹½¨¹¤¾ß¹¹½¨µÄ£¬ÄÇôÕâЩÒÀÀµ¶ÔÄãÀ´Ëµ¾ÍÊÇÒþʽµÄ£¬µ±ÊÔͼʹÓÃÕâЩ¿âʱ£¬ÄãºÜ¿ÉÄÜ»áÓöµ½ClassNotFoundException¡£

ÕýÈçNeil BartlettÔÚ¡± No Solution for Complexity?¡±[3]ÖÐÌáµ½µÄÄÇÑù£¬ÎÒÃÇÐèÒªÒ»ÖÖ·½Ê½ÔÚ´óÐÍϵͳµÄ²»Í¬²¿·Ö´´½¨¡±·À»ðǽ¡±£¬µ±ÔÚÊܵ½¡±·À»ðǽ¡±±£»¤µÄÿ¸ö²¿·ÖµÄÍⲿÔö¼Óй¦ÄÜʱ£¬Äܹ»È·±£ÕâЩÊܵ½±£»¤µÄ²¿·Ö²»»á±»¹¥»÷ºÍÆÆ»µ¡£ÕâÑùµÄ»°£¬ÎÒÃǾÍÄܹ»¾«È·µØÖªµÀϵͳµÄÈκθıäËùÉæ¼°µÄ·¶Î§£¬È»ºó½ö½öÕë¶ÔÕâЩ·¶Î§×ö²âÊÔ£¬¶ø²»ÊÇÈ«²¿¡£

ÁíÒ»·½Ã棬ӦÓóÌÐòµÄÂß¼­±äµÃ¸üΪ¸´ÔÓ£¬½ñÌìµÄÆóÒµÓ¦ÓóÌÐòͨ³£ÒªÖ§³Ö²¢·¢·ÃÎÊ¡¢Ô¶³Ì·ÃÎÊ¡¢³Ö¾Ã»¯Êý¾Ý¡¢ÊÂÎñ²Ù×÷¡¢×é¼þ»¯ºÍ·Ö²¼Ê½(ΪÁË¿¼ÂÇÉìËõÐԺ͸ºÔؾùºâµÈ)¡­¡­ºÁÎÞÒÉÎÊ, JavaEEÒѾ­ÌṩÁËһϵÁÐÊÂʵµÄ±ê׼ȥÂú×ãÕâЩÐèÇ󣬲¢ÇÒ»ñµÃÁ˾޴óµÄ³É¹¦¡£

µ«ÊÇ£¬ÕýÈçHolly CumminsºÍTimothy Ward[2]Ìáµ½µÄ£¬ÎÒÃÇµÄÆóÒµ¼¶Ó¦ÓóÌÐò´øÓÐWebǰ¶Ë¡¢³Ö¾Ã»¯×é¼þ¡¢ÊÂÎñ×é¼þµÈ£¬²¢ÇÒÔËÐÐÔÚ¶à¸ö·þÎñÆ÷ÉÏ£¬ËùÓеÄÕâЩ×é¼þÈçºÎÕ³ºÏµ½Ò»ÆðÒ²Ðí²¢²»ÎªÍŶÓÖÐÿ¸ö³ÉÔ±ÖªÏþ£¬ËûÃÇ¿ÉÄܽö½ö¹Ø×¢×Ô¼ºËù±àдµÄÄDz¿·Ö¡£

ÁíÍâ£¬Ëæ×ÅÆóÒµ¼¶Ó¦ÓóÌÐò»®·Ö³ÉÔ½À´Ô½¶àµÄϵͳ£¬ËüÃÇ»áÔËÐÐÔÚ²»Í¬µÄ·þÎñÆ÷ÉÏ£¬ÕâÒâζ×Åÿ¸öϵͳÔËÐеÄclasspath¡¢¿ÉÓõÄÒÀÀµÒÔ¼°Ó¦ÓóÌÐò·þÎñÆ÷±¾ÉíµÄ¼¼ÊõʵÏÖ¶¼¿ÉÄÜ´óÏྶͥ£¬¶ÔÓÚÕâЩ»¥Ïà¹ØÁªµÄϵͳ£¬×îºÃÊDZÜÃâÖ¸¶¨ËüÃǵÄÒÀÀµÀ´×ÔÄÄÀïÒÔ¼°ÏµÍ³µÄclasspathÊÇÈçºÎ¹¹ÔìµÄ¡£·ñÔò£¬¶ÔÆäÖÐÒ»¸öϵͳ×ö¸Ä±äºÜ¿ÉÄÜ¶ÔÆäËûϵͳÓкܴóµÄÓ°Ïì¡£

Òò´Ë£¬JavaEEÉõÖÁ±È±ê×¼Java¸üÐèҪΪËüµÄÓ¦ÓóÌÐòÄ£¿é»¯¡£

½èÖúOSGiÐÞ¸´ÕâЩÎÊÌâ

µ±Ç°£¬OSGiºÜºÃµØ½â¾öÁËÉÏÊöµÄÕâЩ²»×ã¡£¼òµ¥µØËµ£¬OSGiʹÓúËÐÄJavaÖеÄClassLoader²¢À©Õ¹JARÇåµ¥(manifest)À´´´½¨Ò»¸ö±ÈºËÐÄJava¸ü¾ßÓÐÄ£¿é»¯µÄϵͳ¡£

OSGiÊÇÒ»¸ö´óµÄ»°Ì⣬Èç¹ûÒªÇåÎúµØÀí½âËü£¬ÐèÒª¸ü¶àµÄƪ·ùÈ¥½éÉÜ£¬Èç¹ûÄãÊǵÚÒ»´Î½Ó´¥OSGi,½¨ÒéÊ×ÏÈÔĶÁ[4],ÕâÊÇÎÒ¼ûµ½¹ýµÄ×îºÃµÄOSGiÊé¼®Ö®Ò»¡£

InfoQÔø¾­ÍƳö¹ýÒ»¸öϵÁÐÀ´ÌÖÂÛÄ£¿é»¯ºÍOSGiÏà¹ØµÄ֪ʶ£ºÄ£¿é»¯Java¼ò½é¡¢Ä£¿é»¯Java£º¾²Ì¬Ä£¿é»¯¡¢Ä£¿é»¯Java£º¶¯Ì¬Ä£¿é»¯ÒÔ¼°Ä£¿é»¯Java£ºÉùÃ÷ʽģ¿é»¯¡£ÎªÁ˼æ¹ËһЩ¶ÁÕß(Ò²ÐíËûÃǵÄʱ¼äÓÐÏÞ)£¬ÎÒÃǽö½éÉÜOSGiµÄ¼¸¸öÖØÒª¸ÅÄÏëÁ˽â¸ü¶àÐÅÏ¢µÄ¶ÁÕß¿ÉÒԲο¼ÒÔÉÏÌá¼°µÄÎÄÏ׺ÍÎÄÕ¡£

Àí½âOSGi»ù±¾¸ÅÄî

OSGi BundleºÍBundleµÄ°æ±¾

OSGi BundleÊÇÓɱê×¼JARÒÔ¼°ÔÚJARÇåµ¥ÖмÓÉÏһЩ¶îÍâµÄOSGiÔªÊý¾ÝËù¹¹³É¡£

OSGiÔËÐÐʱ³£³£±»³Æ×÷¡±OSGi¿ò¼Ü¡±£¬ÓÃÀ´¹ÜÀíOSGi BundleµÄÉúÃüÖÜÆÚ²¢¹¹½¨¸÷¸öBundleÖ®¼äµÄÒÀÀµ¹ØÏµ¡£ÔÚOSGiÔËÐÐʱµÄÍâÃæ£¬BundleºÍ±ê×¼JARûÓÐÁ½Ñù£¬µ«ÊÇ£¬ÔÚOSGiÔËÐÐʱ֮ÖУ¬Çé¿öÔòÍêÈ«²»Í¬£¬Ò»¸öBundleÖеÄÀàÄܹ»Ê¹ÓÃÁíÒ»¸öBundleÖÐÀ࣬µ«ÊÇ£¬ÕâÀïÓиöǰÌᣬÄǾÍÊÇÁíÒ»¸öBundleÒªÏÔʽµØÔÊÐíËüµÄÀà±»·ÃÎÊ£¬·ñÔò£¬OSGiÔËÐÐʱ½«×èÖ¹¶ÔÕâ¸öBundleÖÐÀàµÄ·ÃÎÊ¡£Õâ¸ö·ÃÎʹæÔò·Ç³£ÀàËÆJavaÓïÑÔÖеĿɼûÐÔÐÞÊηû(public,private,protectÒÔ¼°°ü¼¶Ë½ÓÐ)¡£

OSGiÔËÐÐʱ»áͨ¹ýÒÀÀµ½âÎö£¬½«Ã¿¸öBundle¹ØÁªÆðÀ´£¬ÐγÉÒ»¸öÒÀÀµµÄͼ£¬

ͼ3: OSGiÈø÷¸öÄ£¿éÖ®¼äµÄÒÀÀµ¸ü¼ÓÇåÎú¡£

Ïà±È½Ïͼ2»ìÂҵĽṹ£¬´Óͼ3ÖУ¬ÎÒÃÇÄܹ»ÇåÎúµØÊ¶±ð¸÷¸öÄ£¿éÖ®¼äµÄÒÀÀµ£¬ÕâÒ»Çж¼Òª¹é¹¦ÓÚOSGi¡£

ÁíÒ»·½Ã棬×îÖØÒªµÄÒ»µãÊÇͨ¹ýBundleµÄ°üµ¼ÈëºÍµ¼³ö»úÖÆ£¬Äã²»±ØÔÙµ£ÐÄ»ò²Â²âÔÚÓ¦ÓóÌÐòÔËÐÐʱ»á¶ªÊ§ÄÄЩÒÀÀµ£¬ÒòΪ£¬Ò»µ©ÕæµÄ¶ªÊ§ÁËÕâЩÒÀÀµ£¬OSGiÔËÐÐʱ»á¼ì²â³ö¶ªÊ§µÄÒÀÀµ£¬È»ºóÅ׳öÒì³££¬¸ù¾ÝÒì³£ÄãÄܹ»×¼È·µØ·ÖÎö³ö¶ªÊ§ÁËÄÄЩÒÀÀµÒÔ¼°ÕâЩÒÀÀµµÄ°æ±¾¡£

µ±È»£¬ÎªÁËÍêÈ«Ïû³ýclasspathµØÓüÖеİ汾³åÍ»£¬OSGi BundleÐèÒª°æ±¾»¯¡£Ê¹ÓÃOSGiÄܹ»ÈþßÓв»Í¬°æ±¾µÄ¿â(ÔÚOSGi»·¾³ÖУ¬ÎÒÃdzÆÖ®ÎªÄ£¿é»òBundle)ÒÔ¼°µ¼³öµÄ°ü¹²´æ£¬Í¬Ê±£¬¶ÔÓÚÒÀÀµ²»Í¬°æ±¾µÄ¿âºÍ°üµÄÄ£¿éÀ´Ëµ£¬ËüÃÇÄܹ»Ñ¡Ôñ×îÊʺϵÄÒÀÀµ¿â¡£Èç¹ûÒÀÀµµÄ¿âûÓа汾»¯£¬ÄÇô¾ÍûÓа취֪µÀ¾É¿âºÍпâÖ®¼äµÄ²îÒ죬ÎÒÃÇ»áÔÙ´ÎÏÝÈëclasspathµØÓü¡£

ÏÞÓÚÆª·ù£¬¹ØÓÚOSGi BundleÔªÊý¾ÝºÍ°æ±¾»¯£¬¸ü¶àµÄÄÚÈÝÇë¶ÁÕß¿´Ò»ÏÂ[2]ºÍ[4]¡£

OSGiµÄ¶¯Ì¬ÐÔºÍÉúÃüÖÜÆÚ¹ÜÀí

¶¯Ì¬ÐÔ¶ÔÓÚÈí¼þ¹¤³Ì²¢²»ÊÇеĸÅÄµ«ÊÇ£¬ËüÊÇOSGiµÄ»ù´¡ºÍºËÐÄ¡£ÄãÒ²Ðí»á˵£¬Í¨¹ý·´Éä¡¢¶¯Ì¬´úÀíÒÔ¼°URLClassLoader£¬Ò²Äܹ»ÊµÏÖ¶¯Ì¬ÐÔ£¬ÄÇô£¬OSGiΪʲô»áΪ¶¯Ì¬ÐÔ½¨Á¢Ò»¸öеÄÄ£ÐÍÄØ£¿

¼òµ¥µØËµ£¬Í¨¹ýÒÔÉϵķ½Ê½À´ÊµÏÖ¶¯Ì¬ÐÔÊÆ±ØÒªÀûÓÃJavaµ×²ãµÄAPI£¬¶øOSGiÊÔͼΪ¿ª·¢ÈËÔ±ÌṩһÖÖ¸ü¼Ó·½±ãºÍÓѺõķ½Ê½À´´ïµ½ÕâһĿ±ê¡£

BundleµÄÉúÃüÖÜÆÚ

Bundle²»ÏñÆÕͨµÄJARÄÇÑù°²¾²µØ´ôÔÚCLASSPATHÖУ¬BundleÄܹ»¸ù¾ÝÐèÒªÆô¶¯ºÍÍ£Ö¹£¬Ò»µ©BundleÆô¶¯ÁË£¬ÄÇÒâζ×ÅËüµÄËùÓе¼ÈëÒÀÀµ¶¼±»Âú×ãÁË¡£BundleµÄÆô¶¯ºÍÍ£Ö¹¹ý³Ì¾ÍÏñÒ»¸ö״̬»úÒ»Ñù£¬Í¨¹ýÏÂͼ£¬ÎÒÃÇÄܹ»ÇåÎúµØ·¢ÏÖBundleµÄÉúÃüÖÜÆÚÖеĸ÷¸ö½×¶Î£º

ͼ4: BundleµÄÉúÃüÖÜÆÚÖеĸ÷¸ö½×¶Î¡£

BundleÄܹ»ÔÚÒѰ²×°(Installed)¡¢ÒѽâÎö(Resolved)¡¢ÕýÔÚÆô¶¯(Starting)¡¢ÒÑÆô¶¯(Active)¡¢ÕýÔÚÍ£Ö¹(Stopping)ÒÔ¼°ÒÑÐ¶ÔØ(Uninstalled)Õâ6¸ö״̬ÖнøÐÐÇ¨ÒÆ¡£

ÕýÔÚÆô¶¯(Starting)ºÍÕýÔÚÍ£Ö¹(Stopping)¸ü¶àµÄÊÇÒ»¸öÔÝ̬£¬ÀýÈ磬µ±Æô¶¯Íê³ÉÖ®ºó£¬Bundle½«½øÈëÒÑÆô¶¯×´Ì¬¡£Bundle´¦ÔÚ½âÎö״̬µÄÌõ¼þÊÇËüÒѾ­±»°²×°£¬²¢ÇÒËüµÄËùÓÐÒÀÀµ¶¼±»½âÎö»òÕß˵±»Âú×ã¡£µ±Ò»¸öBundle±»Ð¶ÔØÊ±£¬Ëü²»ÔÙÄܹ»Ìṩ°ü¸øÈκÎеÄBundle¡£

¹ØÓÚOSGiµÄÆäËûһЩ¸ÅÄîÈç·þÎñÓë·þÎñ×¢²á±í¡¢ClassLoadingµÈ£¬ÏÞÓÚÆª·ù£¬Ã»Óа취һһ½éÉÜ£¬ÏêϸµÄÄÚÈÝÒ²Çë¶ÁÕ߲ο¼[2]ºÍ[4]¡£

»Øµ½ÎÒÃǵÄÎÊÌâ,Ò²ÐíÄã»áÎÊ£¬¼ÈÈ»ºÜ¶àÓ¦Ó÷þÎñÆ÷³§ÉÌÒѾ­²ÉÓÃÁËOSGi×÷ΪËüÃǵÄÄںˣ¬ÊÇ·ñÎÒÃÇ¿ÉÒÔ¼òµ¥µØ½«ÆóÒµ¼¶JavaºÍOSGiÏà½áºÏ£¿

ºÜ²»ÐÒ£¬´ð°¸ÊÇ·ñ¶¨µÄ£¬ÒòΪһЩԭÒò£¬JavaEE±à³ÌÄ£ÐÍÓëOSGi²¢²»¼æÈÝ£¬¹ØÓÚÕâÒ»µã£¬Holly CumminsºÍTimothy Ward[2]¸ø³öÁËÇåÎúµÄ½âÊÍ¡£

ΪʲôOSGiºÍJavaEE²»ÄܺܺõؽáºÏ£¿

¿ò¼ÜºÍÀà¼ÓÔØ

µäÐ͵ÄJavaEEÓ¦Ó÷þÎñÆ÷»áפÁô¶à¸öÆóÒµ¼¶JavaÓ¦ÓóÌÐò£¬ÎªÁËÔÚÕâЩӦÓóÌÐòÖ®¼äÌṩijÖÖ²ã´ÎµÄ¸ôÀ룬JavaEEÓ¦Ó÷þÎñÆ÷»á½¨Á¢Ò»¸öÑϸñµÄÀà¼ÓÔØÌåϵ£¬Í¨¹ýÕâ¸öÀà¼ÓÔØÌåϵ£¬Ó¦ÓóÌÐòÖ®¼äÏ໥¸ôÀë(ÕâÀïµÄ¸ôÀëÖ¸µÄÊÇÓ¦ÓóÌÐòÖ®¼ä²»ÄÜ»¥Ïà·ÃÎʸ÷×ÔµÄ×ÊÔ´)£¬Ó¦ÓóÌÐòÓëÓ¦Ó÷þÎñÆ÷Ö®¼äÒ²Ï໥¸ôÀë¡£Õâ¸öÀà¼ÓÔØÌåϵ»ùÓÚ±ê×¼JavaµÄClassLoaderÌåϵ[6]¡£ÒÔÏÂÊÇÒ»¸öµäÐ͵ÄJavaEEÓ¦Ó÷þÎñÆ÷µÄÀà¼ÓÔØÌåϵ£¬

ͼ5: Ò»¸öµäÐ͵ÄJavaEEÓ¦Ó÷þÎñÆ÷µÄÀà¼ÓÔØÌåϵ

Èçͼ5Ëùʾ£¬Ã¿Ò»¸öClassLoader½ö½öÄܹ»¼ÓÔØËü×Ô¼ººÍËü׿Ïȶ¨ÒåµÄÀ࣬Ëü²»¿ÉÄܼÓÔØµ½Í¬µÈ²ã´ÎµÄÆäËûClassLoader¶¨ÒåµÄÀà¡£Òò´Ë£¬¶ÔÓÚһЩϣÍû±»EJBºÍWEB¹²ÏíµÄÀàÀ´Ëµ£¬ËüÃDZØÐëÒª·ÅÖõ½¸ü¸ßµÄ²ã´Î(ÀýÈç, EAR ClassLoader)£¬ÁíÍ⣬Èç¹ûÓÐһЩÀàÏ£Íû±»ËùÓÐÓ¦ÓóÌÐò¹²Ïí£¬ÄÇô£¬ËüÃDZØÐëÒª·ÅÖõ½Application ClassLoaderÖУ¬Í¨³££¬ÕâÊÇͨ¹ýÅäÖÃÓ¦Ó÷þÎñÆ÷±¾ÉíÀ´´ïµ½µÄ¡£

ÁíÒ»·½Ã棬´Óͼ5ÎÒÃÇÄܹ»·¢ÏÖÓ¦ÓóÌÐòµÄÀ಻¿ÉÄܺÜÈÝÒ׵ر»Ó¦Ó÷þÎñÆ÷±¾ÉíµÄÀà¼ÓÔØ£¬ÕâËÆºõ²»ÊÇʲô´óµÄÎÊÌ⣬µ«ÊÇÓ¦Ó÷þÎñÆ÷ÖеÄһЩÈÝÆ÷ΪӦÓóÌÐòÌṩÁ˲åÈëµã»òÕß˵¡±¹³×Ó¡±£¬Í¨¹ý»Øµ÷Ó¦ÓóÌÐòµÄ´úÂëÀ´Íê³ÉһЩ¹²Í¨µÄÂß¼­¡£Òò´Ë£¬Ó¦Ó÷þÎñÆ÷±ØÐëÒª·ÃÎÊÓ¦ÓóÌÐòµÄÀà¡£

Õâ¸öÎÊÌâͨ¹ýÏß³ÌÉÏÏÂÎÄClassLoader(Thread Context ClassLoader)[8]Äܹ»»Ø±Ü¡£Í¨¹ýÕýÈ·µØÉèÖÃÏß³ÌÉÏÏÂÎÄClassLoader£¬¿ò¼ÜÄܹ»¼ìË÷Õâ¸öClassLoader£¬È»ºó·ÃÎÊÓ¦ÓóÌÐòÒÔ¼°ËüµÄÄ£¿éÖеÄÀà¡£µ«ÊÇ£¬ÕâÒ²Òâζ×Å£¬

Ïß³ÌÉÏÏÂÎÄClassLoader±ØÐëÔÚ¿ò¼Ü¼ìË÷Ëü֮ǰÔÚÆäËûµØ·½ÕýÈ·µØ±»ÉèÖ㬵«ÊÇ£¬ÔÚOSGiÖУ¬Ïß³ÌÉÏÏÂÎÄClassLoaderͨ³£²¢²»»á±»ÉèÖá£
ʹÓÃÏß³ÌÉÏÏÂÎÄClassLoaderÍêȫΥ·´ÁËϵͳµÄÄ£¿é»¯£¬²»Äܱ£Ö¤ÓÉÏß³ÌÉÏÏÂÎÄClassLoader¼ÓÔØµÄÀà»áÆ¥ÅäÄãµÄÀà¿Õ¼ä¡£¹ØÓÚÕâÒ»µã£¬¿ÉÒÔÏëÏóһϣ¬Èç¹ûÏß³ÌÉÏÏÂÎÄClassLoader¼ÓÔØÁËÒ»¸öÀàAµÄ¾É°æ±¾£¬¶øÄãµÄÀà¿Õ¼äÏ£ÍûÆ¥ÅäÀàAµÄа汾£¬ÄÇô£¬ÕâÖÖ²»Æ¥Å佫µ¼Ö´óµÄÎÊÌâ¡£

ÎÒÃÇÌáµ½£¬ÔÚOSGiÖУ¬Ïß³ÌÉÏÏÂÎÄClassLoader³£³£ºÜÉÙ±»ÉèÖ㬵«ÊÇ£¬·²Ê¶¼²»ÊǾø¶ÔµÄ£¬ÀýÈ磬GlassFish OSGi-JavaEEµÄOSGi/WEBÄ£¿é¾ÍÅäÖÃÁËÏß³ÌÉÏÏÂÎÄClassLoaderÀ´¼ÓÔØÒ»Ð©Ó¦ÓóÌÐòBundleµÄÀà¡£

¹ØÓÚÏß³ÌÉÏÏÂÎÄClassLoaderµÄÌÖÂÛºÍʹÓã¬ÎÒ½¨Òé¶ÁÕß¿´Ò»¿´Neil Bartlett¡¯s ¡°The Dreaded Thread Context Class Loader¡±[9]ÒÔ¼°¡± OSGi Readiness ¡ª Loading Classes¡±[10]£¬ÕâÁ½ÆªÎÄÕ¸ø³öÁËһЩ¾«±ÙµÄ¹Ûµã¡£

META-INF ·þÎñ(META-INF/services)ÓëServiceLoaderģʽ

´ÓJDK6¿ªÊ¼, ³öÏÖÁËÒ»ÖÖÄܹ»·¢ÏÖ¸ø¶¨½Ó¿ÚµÄËùÓÐʵÏÖµÄģʽ,³ÆÖ®ÎªServiceLoader[11](×¢Òâ: ÆÕͨµÄ·´ÉäÎÞ·¨·¢ÏÖ¸ø¶¨½Ó¿ÚµÄËùÓÐʵÏÖ[12])¡£

ÔÚÕâÖÖģʽÏ£¬ÈκÎJAR¶¼Äܹ»×¢²áÒ»¸ö¸ø¶¨½Ó¿ÚµÄʵÏÖ²¢ÇÒ½«ÊµÏÖµÄÃû³Æ·ÅÖÃÔÚÕâ¸öJARµÄMETA-INF/servicesĿ¼ÏµÄÒ»¸öÎļþÖУ¬¸ÃÎļþµÄÃû×ÖÒª¸ù¾ÝËùʵÏֵĽӿÚÀ´ÃüÃû¡£È»ºó£¬Í¨¹ýServiceLoaderµÄload·½·¨À´»ñÈ¡classpathÖеÄËùÓнӿڵÄʵÏÖ¡£ÀýÈ磬ÎÒÃÇÓÐÒ»¸ö½Ó¿ÚJAR(AInf.jar)£¬ÆäÖж¨ÒåÁËÒ»¸ö½Ó¿ÚAInf,

public interface AInf
{
long getCount();
¡­
}

ÎÒÃÇÔÙ¶¨ÒåÒ»¸öAInfµÄʵÏÖJAR(AImpl.jar)£¬ÆäÖж¨ÒåÁËÒ»¸öʵÏÖÀàAImpl£¬

package sample.serviceLoader.internal
public Class AImpl implements AInf
{
¡­
}

È»ºó£¬Java¿Í»§¶Ëͨ¹ýServiceLoader»ñÈ¡AInfµÄËùÓÐʵÏÖ£¬

ServiceLoader loader = ServiceLoader.load(AInf.class);
AInf service = loader.iterator().next();

ÕâÖÖ·½Ê½¶ÔÓÚ±ê×¼JavaÀ´ËµÒѾ­×öµÃºÜºÃÁË£¬µ«ÊÇ£¬ÕýÈç[13]ÖÐÌáµ½µÄÄÇÑù£¬ËüÓÐÒ»¶¨µÄ¾ÖÏÞÐÔ£¬×îÃ÷ÏÔµÄÊǵ±ÔËÐÐʱϣÍû¼ÓÈëеĽӿÚʵÏÖʱ£¬ServiceLoaderģʽ¾Í²»ÄÜ·¢»Ó×÷ÓÃÁË£¬Ò²¾ÍÊÇ˵£¬ServiceLoader²»¾ßÓж¯Ì¬µÄ¿ÉÀ©Õ¹ÐÔ¡£

»Øµ½OSGiµÄ»°Ì⣬µ±Ï£Íû½«ÕâÑùµÄ´úÂëÒÆÖ²µ½OSGi»·¾³ÖÐʱ£¬ÎÊÌ⽫±äµÃ¸ü¶à¡£

1.ServiceLoaderģʽÀûÓÃÁËÏß³ÌÉÏÏÂÎÄClassLoaderÈ¥·¢ÏÖMETA-INF/servicesĿ¼ÏµÄËùÓеÄ×ÊÔ´¡£¹ØÓÚÏß³ÌÉÏÏÂÎÄClassLoader£¬ÎÒÃÇÔÚÉÏÃæÒѾ­Ìáµ½£¬ÔÚOSGiµÄ»·¾³ÖУ¬Í¨³£²»»á¶¨ÒåÏß³ÌÉÏÏÂÎÄClassLoader£¬ËùÒÔÓпÉÄÜÔì³ÉServiceLoaderģʽʧЧ¡£

2.OSGi»·¾³Ï£¬BundleÖ®¼äµÄÁªÏµÊÇͨ¹ý¡± Import-Package¡±ºÍ¡±Export-Package¡±ÊµÏֵ쬶ÔÓÚÒ»¸ö¸ø¶¨µÄµ¼È룬ֻÄÜÓÐÒ»¸öÈ·¶¨µÄµ¼³ö£¬Òò´Ë£¬²»¿ÉÄÜͨ¹ýServiceLoaderģʽÀ´»ñÈ¡½Ó¿ÚµÄ¶à¸öʵÏÖ¡£

3.³õʼ»¯Ò»¸ö½Ó¿ÚµÄʵÏÖÒ»°ãÐèÒª·ÃÎÊʵÏÖÀàµÄÄÚ²¿Ï¸½Ú£¬ÀýÈ磬ÎÒÃǵÄAImplÀඨÒåÔÚ*..internal°üÖУ¬¶ÔÓÚOSGiÀ´Ëµ£¬BundleÒ»°ã¶¼²»»áµ¼³öÄÚ²¿µÄϸ½Ú(ÒòΪÕâ»á´òÆÆBundleµÄ·â×°ÐÔ)£¬Òò´Ë£¬ServiceLoaderģʽҲ½«Ê§Ð§¡£¼´±ãÄܹ»µ¼³öÄÚ²¿µÄϸ½Ú£¬½«¿Í»§¶Ë°ó¶¨µ½¾ßÌåµÄʵÏÖ£¬ÕâÒ²»áÎ¥·´ËÉñîºÏµÄ×¼Ôò¡£

4.BundleÓж¯Ì¬µÄÉúÃüÖÜÆÚ£¬Òâζ×ÅʵÏÖBundleºÜ¿ÉÄÜÇÄÎÞÉùÏ¢µÄÀ뿪OSGiÔËÐÐʱ£¬µ«ÊÇ£¬ServiceLoaderģʽ²¢Ã»ÓÐÌṩһÖÖʼþ»úÖÆÀ´Í¨Öª¿Í»§¶Ë¡£

JavaEEûÓÐʵÏÖ¶¯Ì¬µÄÖ´Ðл·¾³

ÓÉÓÚ±ê×¼JavaµÄÖÖÖÖ²»×ãÒÔ¼°JavaEEÓ¦Ó÷þÎñÆ÷µÄÀà¼ÓÔØÌåϵ£¬JavaEE²¢Ã»ÓÐʵÏÖ¶¯Ì¬µÄÖ´Ðл·¾³£¬ÕâÒâζ×ŵ±ÄãµÄWEBÓ¦ÓóÌÐò»òÕßEJBÄ£¿é±»²¿Êð²¢ÇÒÖ´ÐÐʱ£¬Äã²»¿ÉÄÜÔÙÌí¼ÓеÄServlet/JSP»òÕ߸üÐÂEJBÄ£¿é¡£Ó¦ÓóÌÐòËùÄÜ·¢»ÓµÄ·¶Î§±»°ó¶¨ÔÚÁ˲¿Êðʱ¡£

ÐÒÔ˵ÄÊÇ£¬Ëæ×ÅÆóÒµ¼¶OSGiµÄ³öÏÖ£¬OSGiºÍJavaEEÖ®¼äµÄºè¹µÒѾ­±äµÃÔ½À´Ô½Ð¡ÁË¡£

ÆóÒµ¼¶OSGiÓëJavaEEµÄ¼¯³É

2007Äê6Ô£¬OSGiÁªÃË(OSGi Alliance)·¢²¼ÁËOSGi Service Platform Release 4.1£¬ÔÚÕâ¸öReleaseÖУ¬Ê״μÓÈëÁËÃæÏòÆóÒµ¼¶OSGiµÄ¹æ·¶£¬µ½2013Ä꣬OSGiÆóҵר¼Ò×é(EEG)ÒѾ­·¢²¼ÁËOSGi Enterprise Release 5µÄ×îÖÕDraft£¬ÔÚÕâ¸öRelease 5ÖУ¬¼ÓÈëÁ˸ü¶àµÄÃæÏòÆóÒµOSGiµÄ·þÎñ¹æ·¶¡£

ÎÒÃDZØÐëÒªÖ¸³ö£¬Èç¹ûÆóÒµ¼¶OSGi²»ÄÜÌṩ¸ü¶àÔÚJavaEEÖÐÒ²¿ÉÓõķþÎñ£¬ÄÇôÆóÒµ¼¶OSGi½«±äµÃºÁÎÞÓô¦£¬ÒòΪ£¬¶ÔÓÚJavaEEÀ´Ëµ£¬ÒѾ­»ýÀÛÁ˷dz£ÅÓ´óµÄ¿ª·¢ÈºÌ壬ÉçÇøÒѾ­±äµÃ·Ç³£³ÉÊ죬Èç¹ûÆóÒµ¼¶OSGiÌṩÁËÍêÈ«²»Í¬ÓÚJavaEEµÄ¹æ·¶»ò×ö·¨£¬ÄÇô½«¶ÔJavaEEÉçÇøµÄ¿ª·¢ÈºÌåºÁÎÞ°ïÖú£¬Ò²²»¿ÉÄܵõ½¸ü¶àÈ˵ÄÈÏͬ¡£

¹ØÓÚÕâÒ»µã£¬Ò²ÕýÊÇÇý¶¯ÆóÒµ¼¶OSGi²»¶ÏÏòǰ·¢Õ¹µÄ¸ù±¾ËùÔÚ¡£

ÆóÒµ¼¶OSGiµÄ¹æ·¶ºÜ¶à£¬¸²¸ÇÁËÐí¶àÓëJavaEE¼¯³ÉµÄ·þÎñ¡£ÀýÈ磬

1¡¢WEBÓ¦ÓóÌÐò¹æ·¶

Ò»¸öOSGi°æ±¾µÄWEBÓ¦ÓóÌÐò¹æ·¶(chapter 128 in the OSGi Enterprise Release 5 Specification[14])£¬Õâ¸ö¹æ·¶µÄÄ¿µÄÊÇΪÁ˲¿ÊðÒ»¸ö¼È´æµÄºÍеÄWEBÓ¦ÓóÌÐòµ½ÔËÐÐÔÚOSGi¿ò¼ÜÖеÄServletÈÝÆ÷À¶ø²¿ÊðµÄÄ£ÐÍÓ¦¸ÃÀàËÆÓÚJavaEE»·¾³ÖÐWEBÓ¦ÓóÌÐòµÄ²¿Êð¡£

Õâ¸ö¹æ·¶¶¨ÒåÁË¡°Web Application Bundle(WAB)¡±£¬ ËüÊÇÒ»¸öBundleÇÒÓëJavaEEÖÐWARÖ´ÐÐͬÑùµÄ½ÇÉ«¡£WABʹÓÃÁËOSGiµÄÉúÃüÖÜÆÚÒÔ¼°OSGiµÄÀà/×ÊÔ´¼ÓÔØ¹æÔò¶øÃ»ÓÐʹÓñê×¼JavaEE»·¾³µÄ¼ÓÔØ¹æÔò¡£WABÊdz£¹æµÄBundle£¬Òò´ËÄܹ»Ê¹ÓÃOSGi¿ò¼ÜÖеÄËùÓÐÌØÐÔ¡£

Ò»¸ö´«Í³µÄWARÒ²Äܹ»×÷ΪWAB½øÐа²×°£¬ÕâÊÇͨ¹ýÇåµ¥ÖØÐ´À´Íê³ÉµÄ¡£¹ØÓÚÕâÒ»µã£¬GlassFish 4.0ÒѾ­ÊµÏÖÁËÕâ¸öÌØÐÔ¡£

2¡¢JPA·þÎñ¹æ·¶

Java³Ö¾Ã»¯APIÊÇJavaEEÖÐÒ»¸öÖØÒªµÄ¹æ·¶¡£JPAÌṩÁËÒ»¸ö¶ÔÏó¹ØÏµÓ³Éä(ORM)Ä£ÐÍ£¬Õâ¸öÄ£ÐÍͨ¹ý³Ö¾Ã»¯ÃèÊö·ûÀ´ÅäÖá£ÆóÒµ¼¶OSGiµÄJPA·þÎñ¹æ·¶(chapter 127 in the OSGi Enterprise Release 5 Specification[14])¶¨ÒåÁ˳־û¯µ¥ÔªÈçºÎÄܹ»±»·¢²¼µ½OSGi¿ò¼ÜÖС¢¿Í»§¶ËBundleÈçºÎ·¢ÏÖÕâЩ³Ö¾Ã»¯µ¥Ôª£¬ÒÔ¼°Í¨¹ýOSGi JDBC¹æ·¶ÈçºÎÄܹ»·¢ÏÖÊý¾Ý¿âÇý¶¯µÈ¡£

³ýÁËÉÏÊöÁ½¸ö·þÎñ¹æ·¶Ö®Í⣬»¹ÓÐÐí¶àÓÐÓõķþÎñ¹æ·¶£¬È磬JavaÊÂÎñ·þÎñ¹æ·¶(chapter 123 in the OSGi Enterprise Release 5 Specification[14])ÒÔ¼°BlueprintÈÝÆ÷¹æ·¶(chapter 121 in the OSGi Enterprise Release 5 Specification[14])£¬ºóÕßÊÇÆóÒµ¼¶OSGiÖÐ×îÖØÒªµÄ¹æ·¶Ö®Ò»£¬Á¬Í¬Declarative Services¹æ·¶(chapter 112 in the OSGi Enterprise Release 5 Specification[14])ºÍRFC 193 CDI¼¯³É¹æ·¶[15]£¬¾ù±»ÊÓΪOSGiÖеÄÒÀÀµ×¢Èë¹æ·¶£¬ÎÒÈÏΪÒÀÀµ×¢Èë¹æ·¶ÊÇÆóÒµ¼¶OSGi×îÎüÒýÈ˵ö¹æ·¶Ö®Ò»¡£ÁíÍ⣬Service Loader Mediator¹æ·¶(chapter 133 in the OSGi Enterprise Release 5 Specification[14])µÄÒýÈëÕýÊÇΪÁ˽â¾öÎÒÃÇÔÚÉÏÃæÌáµ½µÄServiceLoaderģʽµÄһЩÎÊÌâ¡£

ÏÞÓÚ±¾×¨ÌâµÄƪ·ù£¬²»ÄÜÒ»Ò»Ìᵽÿ¸ö·þÎñ¹æ·¶£¬¸ÐÐËȤµÄ¶ÁÕß¿ÉÒÔÏêϸÔĶÁOSGi Enterprise Release 5 Specification[14]¡£

½ÓÏÂÀ´£¬ÈÃÎÒÃÇ¿´¿´ÆóÒµ¼¶OSGiÔÚGlassFishÖеÄʵÏÖ×´¿ö¡£

GlassFishÖÐµÄÆóÒµ¼¶OSGi

Ê×ÏÈ, ÎÒÃǽ«ÔٴλعËÒ»ÏÂGlassFishÓëOSGiµÄ¹ØÏµ¡£Æä´Î£¬ÎÒÃǽ«¿´Ò»ÏÂGlassFishÖÐµÄÆóÒµ¼¶OSGi¡£

GlassFishÓëOSGiµÄ¹ØÏµ

Ç°ÃæÒѾ­Ìáµ½£¬×Ô´ÓGlassFish 3.0¿ªÊ¼£¬GlassFishµÄÄÚºËÒѾ­ÍêÈ«²ÉÓÃOSGi£¬²¢ÇÒÄÚºËÓÉһϵÁÐOSGi BundleʵÏÖ¡£µ±Æô¶¯Glassfishʱ£¬Ê×ÏÈÆô¶¯OSGiÔËÐÐʱ(ĬÈϵأ¬OSGiÔËÐÐʱÊÇApache Felix)£¬È»ºó£¬GlassFishͨ¹ýÀ©Õ¹OSGi¿ò¼ÜµÄÅäÖûúÖÆ(¶ÔÓÚApache Felix£¬Îĵµ[5]ºÜºÃµØËµÃ÷ÁË¿ò¼ÜµÄÅäÖÃÊôÐÔ)£¬°²×°²¢ÇÒÆô¶¯ÄÚºËBundle¡£ÓÉÓÚGlassFishÊÇÒ»¸öʵÏÖÁËJavaEE¹æ·¶µÄÓ¦Ó÷þÎñÆ÷£¬Òò´Ë£¬ÊµÏÖJavaEE¹æ·¶µÄ¸÷¸öÈÝÆ÷»òÕß˵×é¼þ¶¼±»°ü×°³ÉÁËOSGi Bundle¡£ÄÇô£¬µ±Æô¶¯GlassFishʱ£¬ÕâЩÈÝÆ÷BundleÒ²½«±»°²×°µ½OSGiÔËÐÐʱÖС£

Àí½âGlassFish OSGi-JavaEE

GlassFish²»½ö½öʵÏÖÁË×îеÄJavaEE¹æ·¶£¬¶øÇÒÒ²±©Â¶JavaEE×é¼þÄ£ÐͺÍAPI¸øOSGiÓ¦ÓóÌÐòBundle£¬»»¾ä»°Ëµ£¬OSGi¿ª·¢ÈËÔ±ÏÖÔÚÒ²Äܹ»Ê¹ÓÃJavaEE×é¼þÄ£ÐÍ(ÀýÈç: JSF¡¢JSP¡¢EJB¡¢CDI¡¢JPA¡¢JTAµÈ)¡£ÕâÕýÊÇÆóÒµ¼¶OSGiËùÏ£Íû´ï³ÉµÄ:ÓëJavaEEÄ£ÐÍÏ༯³É¡£Õâ¶ÔÓÚ´ÓÊÂÆóÒµ¼¶OSGi¿ª·¢ÈËÔ±À´ËµÊǷdz£ÖØÒªµÄ£¬ÒòΪËûÃÇÏÖÔÚ¼ÈÄܹ»Ê¹ÓÃJavaEEµÄÇ¿´ó¶ø³ÉÊìµÄÌØÐÔ£¬ÓÖÄܹ»´ïµ½OSGiÄ£¿é»¯ÒÔ¼°ÃæÏò·þÎñËù´øÀ´µÄºÃ´¦¡£

ÔÚGlassFishÖУ¬JavaEEƽ̨µÄ·þÎñ(ÀýÈç: ÊÂÎñ·þÎñ¡¢HTTP·þÎñ¡¢JMS·þÎñµÈ)¶¼±»ÊÓΪOSGi·þÎñ£¬Òò´Ë£¬OSGiÓ¦ÓóÌÐòBundleÄܹ»Í¨¹ýOSGi·þÎñ×¢²á±íÈ¥»ñÈ¡ÕâЩ·þÎñ¡£

Òò´Ë£¬ÎÒÃǸøGlassFish OSGi-JavaEE×öÒ»¸ö׼ȷµÄ¶¨Òå:

¡°GlassFish¿ªÆôÁËOSGiºÍJavaEEµÄË«Ïò½»»¥¡£Ò»·½Ã棬ÓÉOSGi¿ò¼Ü¹ÜÀíµÄOSGi·þÎñÄܹ»¼¤»îÓÉJavaEEÈÝÆ÷¹ÜÀíµÄJavaEE×é¼þ¡£ÁíÒ»·½Ã棬ÓÉJavaEEÈÝÆ÷¹ÜÀíµÄJavaEE×é¼þÄܹ»¼¤»îÓÉOSGi¿ò¼Ü¹ÜÀíµÄOSGi·þÎñ¡£¡±

Ó¦ÓóÌÐò¿ª·¢ÈËÔ±Äܹ»ÉùÃ÷ÐԵص¼³öEJB×÷ΪOSGi·þÎñ£¬²»±ØÐ´ÈκÎOSGi·þÎñµ¼³ö´úÂë¡£ÕâÑù¾ÍÔÊÐíÈκδ¿µÄOSGi×é¼þ(ûÓÐÔËÐÐÔÚJavaEEÉÏÏÂÎÄÖÐ)È¥·¢ÏÖÕâ¸öEJB£¬È»ºóÈ¥¼¤»îËüµÄÒµÎñ·½·¨µÈ¡£ÀàËÆµÄ£¬JavaEE×é¼þÄܹ»¶¨Î»ÓÉ·ÇJavaEE OSGi BundleÌṩµÄOSGi·þÎñ£¬È»ºóʹÓÃÕâЩ·þÎñ¡£ÁíÍ⣬ÎÒÃÇÔÚδÀ´×¨ÌâÖн«¿´µ½£¬GlassFishÀ©Õ¹ÁËÉÏÏÂÎÄÒÀÀµ×¢Èë(CDI)ʹµÃJavaEE×é¼þÒÔÀàÐͰ²È«µÄ·½Ê½Ê¹Óö¯Ì¬µÄOSGi·þÎñ¸ü¼ÓµÃ±ãÀû¡£ÒÔÏÂÊÇGlassFishÖÐOSGi-JavaEEÏà¹ØµÄ¸÷¸öÄ£¿éµÄλÖùØÏµ¡£

ͼ6: GlassFishÖÐOSGi-JavaEEÏà¹ØµÄÈÝÆ÷µÄλÖùØÏµ

Õª×Ô: OSGi Application Development using GlassFish Server[16]

ÔÚGlassFish OSGi-JavaEEÖУ¬»ùÓÚOSGi BundleËùʹÓõÄÌØÐÔ£¬ËüÃDZ»»®·Ö³ÉÁ½À࣬

¢Ù ÆÕͨ(plain vanilla)µÄOSGi Bundle

ÕâЩBundle²»°üº¬ÈκÎJavaEE×é¼þÒ²²»Ê¹ÓÃÈκÎJavaEEÌØÐÔ¡£

¢Ú ʹÓÃJavaEEµÄOSGi Bundle(Ò²³Æ×÷ºÏ³ÉÓ¦ÓóÌÐòBundle)

ÕâЩBundle°üº¬JavaEE×é¼þ¡£Òò´Ë£¬ÕâÑùµÄBundle²»½ö½öÊÇÒ»¸öOSGi Bundle£¬¶øÇÒÊÇÒ»¸öJavaEEÖÆÆ·£¨artifact£©¡£

¶ÔÓÚʹÓÃGlassFish OSGi-JavaEE¿ª·¢µÄÓ¦ÓóÌÐòÀ´Ëµ£¬ËüÃÇÄܹ»Ê¹ÓÃÈçÏÂÁ½ÀàAPI£¬

1¡¢OSGi API

Ŀǰ£¬GlassFish 4.0´øÓÐÒ»¸ö·ûºÏOSGi R4.2µÄ¿ò¼Ü£¬Òò´ËËùÓÐOSGi 4.2µÄºËÐÄAPI¶¼¿ÉÓ㬽øÒ»²½µØ£¬GlassFishÒ²´øÓÐÐí¶àÒ»°ãÐÔµÄOSGi·þÎñ£¬ÀýÈ磬

1.OSGiÅäÖÃAdmin·þÎñ

2.OSGiʼþAdmin·þÎñ

3.OSGi Declarative·þÎñ

GlassFishʹÓÃÁËÀ´×ÔApache FelixµÄÕâЩ·þÎñµÄʵÏÖ¡£

2¡¢JavaEE API

Ò»¸öÓû§²¿ÊðµÄOSGi Bundle²»½ö½öÄܹ»Ê¹ÓÃOSGi API£¬¶øÇÒÒ²Äܹ»Ê¹ÓÃJavaEE API¡£ÖµµÃ×¢ÒâµÄÒ»µãÊÇ£¬GlassFish 4ÊÇÒ»¸öʵÏÖÁËJavaEE 7µÄÓ¦Ó÷þÎñÆ÷£¬Òò´Ë£¬Óû§Äܹ»Ê¹ÓÃ×îеÄJavaEE API¡£µ«ÊÇ£¬²¢·ÇËùÓÐJavaEE API¶¼¶Ô¸÷ÖÖÀàÐ͵ÄOSGi Bundle¿ÉÓã¬

Àà±ðA: ÓÉJavaEEÈÝÆ÷¹ÜÀíµÄ×é¼þ£¬ÀýÈ磬EJB¡¢CDI¡¢Servlet¡¢JSFÒÔ¼°JAX-RSµÈ¡£ÕâЩ×é¼þÓÉÈÝÆ÷¹ÜÀí£¬Òò´Ë£¬ËüÃǶÔÓÚÆÕͨ(Plain vanilla)µÄOSGi Bundle²»¿ÉÓã¬ÒòΪÆÕͨµÄOSGi Bundle²»ÊÜJavaEEÔËÐÐʱ¹ÜÀí¡£Ò»¸öOSGi Bundle±ØÐë³ÉΪºÏ³ÉÓ¦ÓóÌÐòBundle²ÅÄܹ»Ê¹ÓÃÕâЩ×é¼þÏà¹ØµÄAPI¡£

Àà±ðB: ·ÃÎÊÆ½Ì¨·þÎñµÄAPI£¬ÀýÈ磬JNDI¡¢ JTA¡¢ JDBCÒÔ¼°JMSµÈ£¬OSGi BundleµÄ¿ª·¢ÈËÔ±Ò²Äܹ»Ê¹ÓÃÕâЩAPI¡£µäÐ͵أ¬Ò»¸öBundle±ØÐëʹÓÃJNDIÈ¥·ÃÎÊ·þÎñºÍ×ÊÔ´£¬µ«GlassFishʵ¼ÊÉÏʹÕâЩƽ̨·þÎñ±ä³ÉÁËOSGi·þÎñ£¬Òò´Ë£¬OSGiÓ¦ÓóÌÐò¿ª·¢ÈËÔ±Äܹ»Ê¹ÓÃOSGi·þÎñAPIÈ¥·ÃÎÊÕâЩƽ̨·þÎñ¡£

Àà±ðC: ¹¦ÄÜAPI£¬ÏñJAXB¡¢JAXPÒÔ¼°JPAµÈ¡£¾ø´ó¶àÊýÕâЩAPI¶¼ÓÐÒ»¸ö²åÈë²ã´Ó¶øÔÊÐíÓ¦ÓóÌÐò²åÈ벻ͬµÄʵÏÖ£¬µäÐ͵أ¬ÕâÖֿɲåÈëÐÔÊÇͨ¹ý±ê×¼JavaµÄServiceLoaderģʽÀ´Íê³ÉµÄ£¬ÎÒÃÇÇ°ÃæÌáµ½¹ý£¬ServiceLoaderģʽÊÇÀûÓÃÁËÏß³ÌÉÏÏÂÎÄClassLoaderÀ´·¢ÏÖ½Ó¿ÚµÄËùÓÐʵÏÖ£¬Òò´Ë£¬±ØÐëÒªÉèÖÃÕýÈ·µÄÏß³ÌÉÏÏÂÎÄClassLoader¡£µ«ÊÇ£¬GlassFishûÓÐÕâÑùµÄÏÞÖÆ£¬¶ÔÓÚ²¿ÊðÔÚGlassFishµÄOSGi BundleÀ´Ëµ£¬¿ÉÒÔ°²È«µØÊ¹ÓÃÕâЩ¹¦ÄÜAPI¡£

ÔÚ½ÓÏÂÀ´µÄ¸÷¸öרÌâÖУ¬ÎÒÃǽ«ÏêϸµØÀí½âGlassFish OSGi-JavaEEµÄ¸÷¸öÄ£¿éÒÔ¼°ÑÝʾÈçºÎ¿ª·¢ºÏ³ÉÓ¦ÓóÌÐòBundleÀ´¸üºÃµØ½áºÏJavaEEºÍOSGi¡£

ÔÚPart2ÖÐÎÒÃǽ«Ê×ÏÈ¿´Ò»ÏÂGlassFish OSGi/WEBÄ£¿é£¬Ò»·½Ãæ´øÁì´ó¼ÒÉîÈëÀí½âOSGi WEB¹æ·¶£¬ÁíÒ»·½ÃæÑ§Ï°ÈçºÎ²¿ÊðÒ»¸öWEB Ó¦ÓóÌÐòBundleµ½GlassFishÖС£

   
3953 ´Îä¯ÀÀ       27
Ïà¹ØÎÄÕÂ

Java΢·þÎñÐÂÉú´úÖ®Nacos
ÉîÈëÀí½âJavaÖеÄÈÝÆ÷
JavaÈÝÆ÷Ïê½â
Java´úÂëÖÊÁ¿¼ì²é¹¤¾ß¼°Ê¹Óð¸Àý
Ïà¹ØÎĵµ

JavaÐÔÄÜÓÅ»¯
Spring¿ò¼Ü
SSM¿ò¼Ü¼òµ¥¼òÉÜ
´ÓÁ㿪ʼѧjava±à³Ì¾­µä
Ïà¹Ø¿Î³Ì

¸ßÐÔÄÜJava±à³ÌÓëϵͳÐÔÄÜÓÅ»¯
JavaEE¼Ü¹¹¡¢ Éè¼ÆÄ£Ê½¼°ÐÔÄܵ÷ÓÅ
Java±à³Ì»ù´¡µ½Ó¦Óÿª·¢
JAVAÐéÄâ»úÔ­ÀíÆÊÎö
×îл¼Æ»®
DeepSeekÔÚÈí¼þ²âÊÔÓ¦ÓÃʵ¼ù 4-12[ÔÚÏß]
DeepSeek´óÄ£ÐÍÓ¦Óÿª·¢Êµ¼ù 4-19[ÔÚÏß]
UAF¼Ü¹¹ÌåϵÓëʵ¼ù 4-11[±±¾©]
AIÖÇÄÜ»¯Èí¼þ²âÊÔ·½·¨Óëʵ¼ù 5-23[ÉϺ£]
»ùÓÚ UML ºÍEA½øÐзÖÎöÉè¼Æ 4-26[±±¾©]
ÒµÎñ¼Ü¹¹Éè¼ÆÓ뽨ģ 4-18[±±¾©]

Java ÖеÄÖÐÎıàÂëÎÊÌâ
Java»ù´¡ÖªÊ¶µÄÈýÊ®¸ö¾­µäÎÊ´ð
Íæ×ª Java Web Ó¦Óÿª·¢
ʹÓÃSpring¸üºÃµØ´¦ÀíStruts
ÓÃEclipse¿ª·¢iPhone WebÓ¦ÓÃ
²å¼þϵͳ¿ò¼Ü·ÖÎö


Struts+Spring+Hibernate
»ùÓÚJ2EEµÄWeb 2.0Ó¦Óÿª·¢
J2EEÉè¼ÆÄ£Ê½ºÍÐÔÄܵ÷ÓÅ
Java EE 5ÆóÒµ¼¶¼Ü¹¹Éè¼Æ
Javaµ¥Ôª²âÊÔ·½·¨Óë¼¼Êõ
Java±à³Ì·½·¨Óë¼¼Êõ


Struts+Spring+Hibernate/EJB+ÐÔÄÜÓÅ»¯
»ªÏÄ»ù½ð ActiveMQ Ô­ÀíÓë¹ÜÀí
ijÃñº½¹«Ë¾ Java»ù´¡±à³Ìµ½Ó¦Óÿª·¢
ij·çµç¹«Ë¾ Java Ó¦Óÿª·¢Æ½Ì¨ÓëÇ¨ÒÆ
ÈÕÕÕ¸Û J2EEÓ¦Óÿª·¢¼¼Êõ¿ò¼ÜÓëʵ¼ù
ij¿ç¹ú¹«Ë¾ ¹¤×÷Á÷¹ÜÀíJBPM
¶«·½º½¿Õ¹«Ë¾ ¸ß¼¶J2EE¼°ÆäÇ°ÑØ¼¼Êõ