Author: skitching
Date: Thu Mar 2 02:02:26 2006
New Revision: 382339
URL: http://svn.apache.org/viewcvs?rev=382339&view=rev
Log:
Fix bug when using explicit classloader to find java services file.
Modified:
jakarta/commons/proper/logging/contrib/simon/jcl2/src/core/java/org/apache/commons/logging/Utils.java
Modified:
jakarta/commons/proper/logging/contrib/simon/jcl2/src/core/java/org/apache/commons/logging/Utils.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/src/core/java/org/apache/commons/logging/Utils.java?rev=382339&r1=382338&r2=382339&view=diff
==============================================================================
---
jakarta/commons/proper/logging/contrib/simon/jcl2/src/core/java/org/apache/commons/logging/Utils.java
(original)
+++
jakarta/commons/proper/logging/contrib/simon/jcl2/src/core/java/org/apache/commons/logging/Utils.java
Thu Mar 2 02:02:26 2006
@@ -45,9 +45,10 @@
* <code>META-INF/services/service.name</code> where service.name
* matches the fully qualified name of the provided base class.
* <p>
- * The file contains a single non-comment line containing the name of
- * the concrete class. An instance of that type will be created, and
- * returned.
+ * The file contains one or more non-comment lines containing the
+ * names of concrete classes that provide an implementation of the
+ * base class. An instance of the first-occurring class will be
+ * created and returned.
* <p>
* The classloader that is used as the base of the search for the
* service file is the one that loaded the specified base class. The
@@ -77,14 +78,19 @@
throws LogConfigurationException {
String serviceName = baseClass.getName();
- String serviceFileName = "/META-INF/services/" + serviceName;
+ String serviceFileName = "META-INF/services/" + serviceName;
InputStream is;
if (baseLoader == null) {
// Don't call baseClass.getClassLoader here, as that may cause
// a SecurityException in some environments. Just use the method
// on the Class object which should have the same effect.
- is = baseClass.getResourceAsStream(serviceFileName);
+ //
+ // Note that when using Class.getResourceAsStream, we need a slash
+ // on the front of the path to prevent the class packagename being
+ // prefixed to the resource. However we must NOT put a slash on the
+ // front when using ClassLoader.getResourceAsStream!
+ is = baseClass.getResourceAsStream("/" + serviceFileName);
} else {
is = baseLoader.getResourceAsStream(serviceFileName);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]