Absolute path of a resource in the classpath [message #242712] |
Wed, 11 April 2007 06:10  |
Eclipse User |
|
|
|
Hi there!
I have to find the absolute path (URL) of a resource that lies in a JAR
file in the classpath of a Java project. All I know is the
classpath-relative path of this resource. With pure Java, this can be
done very easy over the classloader like this:
URL absolute =
this.getClass().getClassLoader().getResource("conf/meta-model/MyModel.edsmm ");
Because I need to do this in a plugin, i can't use the classloder. I
have to do this with help of an IJavaProject.
I know there is a way to get resources by iterating over the package
fragments of the project and doing a getNonJavaResources() at the right
fragment, but this is a very complicated solution with several loops,
sub-loops and checks.
Isn't there an easier way to do this? Normally, using eclipse should
make things simpler ;-).
Thanks
Roger
|
|
|
|
Re: Absolute path of a resource in the classpath [message #242761 is a reply to message #242751] |
Thu, 12 April 2007 04:28  |
Eclipse User |
|
|
|
Thank you for the answer Genady.
Hmmm, correct me if I'm wrong. With getResolvedClasspathEntry() I get an
IClasspathEntry holding the resolved path of a given IClasspathEntry.
An IClasspathEntry represents a library, a JAR or a referenced project.
The problem is, that I don't know in which JAR my resource lies. That is
what I try to find out. I only know that I is somewhere in the projects
classpath.
Roger
Genady wrote:
> Take a look at JavaCore.getResolvedClasspathEntry()
>
> Genady Beryozkin
> http://www.genady.net/
>
>
>
> Roger Villars wrote:
>> Hi there!
>>
>> I have to find the absolute path (URL) of a resource that lies in a JAR
>> file in the classpath of a Java project. All I know is the
>> classpath-relative path of this resource. With pure Java, this can be
>> done very easy over the classloader like this:
>>
>> URL absolute =
>> this.getClass().getClassLoader().getResource("conf/meta-model/MyModel.edsmm ");
>>
>>
>> Because I need to do this in a plugin, i can't use the classloder. I
>> have to do this with help of an IJavaProject.
>>
>> I know there is a way to get resources by iterating over the package
>> fragments of the project and doing a getNonJavaResources() at the
>> right fragment, but this is a very complicated solution with several
>> loops, sub-loops and checks.
>>
>> Isn't there an easier way to do this? Normally, using eclipse should
>> make things simpler ;-).
>>
>> Thanks
>> Roger
|
|
|
Powered by
FUDForum. Page generated in 0.04558 seconds