Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Absolute path of a resource in the classpath
Absolute path of a resource in the classpath [message #242712] Wed, 11 April 2007 10:10 Go to next message
Roger Villars is currently offline Roger VillarsFriend
Messages: 57
Registered: July 2009
Member
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 #242751 is a reply to message #242712] Wed, 11 April 2007 18:00 Go to previous messageGo to next message
Genady Beryozkin is currently offline Genady BeryozkinFriend
Messages: 410
Registered: July 2009
Senior Member
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
Re: Absolute path of a resource in the classpath [message #242761 is a reply to message #242751] Thu, 12 April 2007 08:28 Go to previous message
Roger Villars is currently offline Roger VillarsFriend
Messages: 57
Registered: July 2009
Member
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
Previous Topic:Error opening JarFile
Next Topic:classpathContainerPage edit
Goto Forum:
  


Current Time: Sun Jun 30 13:43:51 GMT 2024

Powered by FUDForum. Page generated in 0.03353 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top