Classloader problem when loading resource files [message #336762] |
Wed, 01 July 2009 11:01  |
Eclipse User |
|
|
|
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 #336776 is a reply to message #336774] |
Wed, 01 July 2009 21:29  |
Eclipse User |
|
|
|
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.
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03540 seconds