JXSE 2.5 : What's Cool #2 -- META-INF/services

http://weblogs.java.net/blog/bondolo/archive/2007/09/jxse_25_whats_c_2.html

——————————————————————————————————————————————————————————————

 

JXSE 2.5 : What's Cool #2 -- META-INF/services

Posted by bondolo on September 12, 2007 at 5:33 PM EDT
JXSE (JXTA for Java SE/EE 5.0) 2.5 contains quite a number of exciting changes for JXTA application developers. This little series will look at a few of the important changes in the upcoming release.

One thing that's cool about working on an open source project is that every so often a community member you've never heard of will speak up and make a brilliant suggestion that even after years of devoted work on the project everyone else somehow missed. Exactly this happened last fall a few weeks before JXSE 2.4.1 went final and unfortunately too late for it to be included in JXSE 2.4.1 but it is now available in JXSE 2.5. The old jxta.org bugzilla was not preserved when we transfered the JXSE project to Java.net, so I have lost track of the name of the user who suggested the feature. If you're willing to step forward and identify yourself I'd be very happy to acknowledge your contribution.

The cool feature which is the subject of this blog is the JAR Service Provider, otherwise known as the META-INF/services system. The META-INF/services system allows for the dynamic registration of instance classes for a particular interface. We are now using it for several of the JXSE class factories and the JXSE Class Loader.

To register classes you list the class names implementing an interface in a file named for the interface in the META-INF/services folder of your JAR file. For example, to register new Advertisement types you include a file "net.jxta.document.Advertisement" in the META-INF/services folder of your JAR containing the full names of your Advertisement classes. During startup the JXSE AdvertisementFactory will read class names from that file and register classes. The process is repeated for each net.jxta.document.Advertisement file in all of the other JARs.

Use of the META-INF/services system makes it much, much easier to extend JXSE by adding your own components. Adding support for your advertisement type to JXSE now requires only including the class names in the net.jxta.document.Advertisement file of your JAR file. You can also register StructuredDocument types, ID formats, WireMessageFormats and JXTA Services and Modules. We have converted JXSE to use the META-INF/services system for all of the core modules.

 

 

转载于:https://www.cnblogs.com/cuizhf/archive/2011/10/24/2222236.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值