I would like to overide the META-INF/services there, will it work without a jar?
-
It seems the answer is yes, but I'd hate to answer my own question so fast. Will let someone else get some reputation... this is in any case a question I couldn't find the answer here or by googling – Eran Medan Mar 27 '11 at 07:38
2 Answers
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).

- 48,905
- 14
- 116
- 132
-
1Thanks, I'm overriding a parent classloader's META-INF/services/javax.xml.transform.TransformerFactory, apparently for that purpose, its a parent-last by default, so I agree it doesn't override the current classloader META-INF content, but it does seem to override the parent's one. See javax.xml.datatype.FactoryFinder.findJarServiceProvider – Eran Medan Mar 27 '11 at 08:48
-
You are right of course :-) I tried to update my answer... You should get the points for that, not me. – Thomas Mueller Mar 27 '11 at 11:22
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.

- 97,814
- 39
- 186
- 310