Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Classloader problem when loading resource files
Classloader problem when loading resource files [message #336762] Wed, 01 July 2009 15:01 Go to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Hello.

I have a classloader problem that I am unable to solve.
Let's assume one plugin (org.core) and one fragment (org.core.test) with tests for that plugin.
org.core now uses a class of a third party library that needs a filepath (as string) of an
configuration XML file.
No problem until now. I simply solve that by using Bundle.getResource() and
FileLocator.toFileURL(url).getPath() to get the correct path of the configuration file.
The problem is now that the configuration file also contains filepaths that are again used by the
third party library, and I don't have any influence of those library classes.
So it comes that those third party library classes can't find the files and throw an exception.

The only two solutions here I see:

- Change the current working directoy.
E.g. if I start a test (from org.core.test) from within the Eclipse workbench, then the current
working directory seems to be /home/kai/.../org.core.test. So I have to change the current working
directoy to /home/kai/.../org.core.

- Dynamically generate the XML configuration file
Regenerate the XML file with the correct file paths each time my application is started.

I don't like both ideas. Any better solutions? If not, how do I change programmatically the working
directory?

Regards,
Kai
Re: Classloader problem when loading resource files [message #336766 is a reply to message #336762] Wed, 01 July 2009 15:10 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
I found out, it's even worse.
The third party libraries also directly use resources relative to the current working directory.
So it seems that changing the current working directory is the only solution.
Are there other solutions?

Regards,
Kai

Kai Schlamp wrote:
> Hello.
>
> I have a classloader problem that I am unable to solve.
> Let's assume one plugin (org.core) and one fragment (org.core.test) with
> tests for that plugin.
> org.core now uses a class of a third party library that needs a filepath
> (as string) of an configuration XML file.
> No problem until now. I simply solve that by using Bundle.getResource()
> and FileLocator.toFileURL(url).getPath() to get the correct path of the
> configuration file.
> The problem is now that the configuration file also contains filepaths
> that are again used by the third party library, and I don't have any
> influence of those library classes.
> So it comes that those third party library classes can't find the files
> and throw an exception.
>
> The only two solutions here I see:
>
> - Change the current working directoy.
> E.g. if I start a test (from org.core.test) from within the Eclipse
> workbench, then the current working directory seems to be
> /home/kai/.../org.core.test. So I have to change the current working
> directoy to /home/kai/.../org.core.
>
> - Dynamically generate the XML configuration file
> Regenerate the XML file with the correct file paths each time my
> application is started.
>
> I don't like both ideas. Any better solutions? If not, how do I change
> programmatically the working directory?
>
> Regards,
> Kai
Re: Classloader problem when loading resource files [message #336774 is a reply to message #336766] Thu, 02 July 2009 01:20 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Kai Schlamp" <schlamp@gmx.de> wrote in message
news:h2fu7v$tme$2@build.eclipse.org...
>I found out, it's even worse.
> The third party libraries also directly use resources relative to the
> current working directory.
> So it seems that changing the current working directory is the only
> solution.
> Are there other solutions?

From what you've said it seems that the problem is happening because by
putting your tests into a separate fragment, you've broken an assumption of
the third-party libraries, namely that they are always called from a process
executing in a certain directory relative to the resources.

Perhaps it is worth exploring whether these third-party libraries can be
fixed? For instance, so that they search for resources on the classpath,
rather than in a relative filesystem path?

If not, another possibility might be to copy the necessary resources into
the test fragment folder.
Re: Classloader problem when loading resource files [message #336776 is a reply to message #336774] Thu, 02 July 2009 01:29 Go to previous message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Thanks Walter.

Thats exaclty the problem. And I already wrote them. But they also provide a solution. A static
class to set the working directory for their party library.
But indeed, loading the resources from the classpath would have made things much more easier. Too
bad that many Java devolopers can't even think of environments where a specific folder structure is
not possible.

Best regards,
Kai

Walter Harley wrote:
> "Kai Schlamp" <schlamp@gmx.de> wrote in message
> news:h2fu7v$tme$2@build.eclipse.org...
>> I found out, it's even worse.
>> The third party libraries also directly use resources relative to the
>> current working directory.
>> So it seems that changing the current working directory is the only
>> solution.
>> Are there other solutions?
>
> From what you've said it seems that the problem is happening because by
> putting your tests into a separate fragment, you've broken an assumption of
> the third-party libraries, namely that they are always called from a process
> executing in a certain directory relative to the resources.
>
> Perhaps it is worth exploring whether these third-party libraries can be
> fixed? For instance, so that they search for resources on the classpath,
> rather than in a relative filesystem path?
>
> If not, another possibility might be to copy the necessary resources into
> the test fragment folder.
>
>
Previous Topic:Various Style Commands in View Toolbar
Next Topic:Problems in cheatsheet passing parameters to commands.
Goto Forum:
  


Current Time: Thu Dec 26 20:25:20 GMT 2024

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

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

Back to the top