Link to home
Start Free TrialLog in
Avatar of sun67
sun67

asked on

getContextClassLoader() returns NULL

Hello,
I have problems with this code:

public class Config   extends CompositeConfiguration {
...      
    /*Default configuration file*/
    private static final String DEFAUL_CONFIG_FILE = "c:\\j\\resources\\properties\\config.xml";
    URL configURL1 = Thread.currentThread().getContextClassLoader().getResource(configFile);
...
}

The problem is configURL1 is always NULL after the code executes. I've hardcoded the full path to config.xml to ensure that its looking in the right place, but still get NULL.
I'm using Eclipse for the IDE.

Does anybody have any ideas ?
Thanks
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could try

URL configURL1 = Thread.currentThread().getContextClassLoader().getResource(new File(DEFAUL_CONFIG_FILE).toURL());

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sun67
sun67

ASKER

I tried

URL configURL1 = Thread.currentThread().getContextClassLoader().getResource(new File(DEFAUL_CONFIG_FILE).toURL().toString());

but it still returns NULL,

I added c:\j\ to the classpath and tried
URL configURL1 = Thread.currentThread().getContextClassLoader().getResource("../resources/properties/config.xml");

that returned NULL as well.

I tried
configFile = "../resources/properties/config.xml";
URL configURL1 = new File(configFile).toURL();

and that works well.  I'm going to have to use getContextClassLoader() alot, so it would be nice to know why it still returns NULL. Otherwise, I'll go ahead and accept as a solution.

Thanks
Make c:\j\ be in the classpath and try
URL configURL1 = Thread.currentThread().getContextClassLoader().getResource("resources/properties/config.xml");
(IE with out the ../)
Avatar of sun67

ASKER

I tried
URL configURL1 = Thread.currentThread().getContextClassLoader().getResource("resources/properties/config.xml");

that is working.
getContextClassLoader() seems to work without the "../". I had to move the folder /resources/ down another level in my project directory but that's ok with me! Thank you both.