D
David Favro
Hello all,
I am trying to access a resource in the jar file which contains the
class that I am currently executing (which is also in my classpath).
So, e.g., I'm executing a method in the class com.foo.Bar, which is
stored in the jar file baz.jar. The contents of baz.jar
(hypothetical, excluding the manifest and all that):
com/foo/Bar.class
com/foo/subDir/myFile
Now I want to access myFile as a resource. Normally, I use
ClassLoader.getResource() with just the unqualified file-name, which
works fine when the file is in the same directory as the package
containing the class that I'm executing, but in this case it isn't
(it's in a subdirectory), and no matter what I try (relative path name
(i.e. subDir/myFile), fully qualified path name (i.e.
com/foo/subDir/myFile), even the pathname preceding it with a leading
'/', Class.getResource(), ClassLoader.getSystemResource(), etc.),
getResource() comes back with null.
The docs ( http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)
) say that a null return could be resource doesn't exist (it does), or
I have "inadequate privileges," but doesn't give any way to determine
which one is the problem, or what "inadequate privileges" means in
this context. I even tried granting myself AllPermission but to no
avail. Is there documentation about how this works? Sun's docs
always leave me trail-and-error-ing because they never explain the
full story (this is the perfect example). Usually I can go to the
source code to figure out how it really works when their documentation
breaks down, but in this case the code that gets resources seems not
to be distributed in source form in the SDK.
So... does anyone know if there is a permission that is needed for
this (I scanned the permission documentation and found nothing),
another reason why it might return null, or, most of all, how I could
lay my hands on the source to sun.misc.URLClassPath (apparently the
code that actually does it, and not in the standard SDK source code
distribution) so I could find out for myself?
Thanks very much in advance!
I am trying to access a resource in the jar file which contains the
class that I am currently executing (which is also in my classpath).
So, e.g., I'm executing a method in the class com.foo.Bar, which is
stored in the jar file baz.jar. The contents of baz.jar
(hypothetical, excluding the manifest and all that):
com/foo/Bar.class
com/foo/subDir/myFile
Now I want to access myFile as a resource. Normally, I use
ClassLoader.getResource() with just the unqualified file-name, which
works fine when the file is in the same directory as the package
containing the class that I'm executing, but in this case it isn't
(it's in a subdirectory), and no matter what I try (relative path name
(i.e. subDir/myFile), fully qualified path name (i.e.
com/foo/subDir/myFile), even the pathname preceding it with a leading
'/', Class.getResource(), ClassLoader.getSystemResource(), etc.),
getResource() comes back with null.
The docs ( http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)
) say that a null return could be resource doesn't exist (it does), or
I have "inadequate privileges," but doesn't give any way to determine
which one is the problem, or what "inadequate privileges" means in
this context. I even tried granting myself AllPermission but to no
avail. Is there documentation about how this works? Sun's docs
always leave me trail-and-error-ing because they never explain the
full story (this is the perfect example). Usually I can go to the
source code to figure out how it really works when their documentation
breaks down, but in this case the code that gets resources seems not
to be distributed in source form in the SDK.
So... does anyone know if there is a permission that is needed for
this (I scanned the permission documentation and found nothing),
another reason why it might return null, or, most of all, how I could
lay my hands on the source to sun.misc.URLClassPath (apparently the
code that actually does it, and not in the standard SDK source code
distribution) so I could find out for myself?
Thanks very much in advance!