开发者

Can META-INF be used in an exploded classes folder (e.g. not within a JAR)?

I would like to overide the META-INF/se开发者_JAVA百科rvices there, will it work without a jar?


Yes, you can use META-INF/services without a jar file. At least that's what happens according to my test (Java 6).

The META-INF directory of all jar files and all directories in the classpath can be scanned independently, so technically such a META-INF file doesn't override the file from another jar file, but (depending on the loader mechanism) entries in one of the files (resource of one of the class loaders) may have priority over other files, so in fact you can overload entries. As you already found out, one such case is javax.xml.datatype.FactoryFinder (I didn't know that).


All classloaders (at least, all rational class loaders) specify an order. Things are searched for from one end to the other. If you add a META-INF directory to either a jar or a directory at the (comparative) front, files in there will be first. If you add it to the end, files in there will be last. If your classloader is parent-first and has a parent, of course it gets the first shot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜