Skip to content
Snippets Groups Projects
Commit 10697402 authored by Matei Zaharia's avatar Matei Zaharia
Browse files

Added a jarOfObject method to get the JAR of the class that an object

belongs to, which seems like a more common case.
parent 0c965a10
No related branches found
No related tags found
No related merge requests found
......@@ -356,21 +356,23 @@ object SparkContext {
// Find the JAR from which a given class was loaded, to make it easy for users to pass
// their JARs to SparkContext
def jarOfClass[T: ClassManifest]: Option[String] = {
val cls = classManifest[T].erasure
def jarOfClass(cls: Class[_]): Seq[String] = {
val uri = cls.getResource("/" + cls.getName.replace('.', '/') + ".class")
if (uri != null) {
val uriStr = uri.toString
if (uriStr.startsWith("jar:file:")) {
// URI will be of the form "jar:file:/path/foo.jar!/package/cls.class", so pull out the /path/foo.jar
Some(uriStr.substring("jar:file:".length, uriStr.indexOf('!')))
List(uriStr.substring("jar:file:".length, uriStr.indexOf('!')))
} else {
None
Nil
}
} else {
None
Nil
}
}
// Find the JAR that contains the class of a particular object
def jarOfObject(obj: AnyRef): Seq[String] = jarOfClass(obj.getClass)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment