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\\propert ies\\confi g.xml";
URL configURL1 = Thread.currentThread().get ContextCla ssLoader() .getResour ce(configF ile);
...
}
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
I have problems with this code:
public class Config extends CompositeConfiguration {
...
/*Default configuration file*/
private static final String DEFAUL_CONFIG_FILE = "c:\\j\\resources\\propert
URL configURL1 = Thread.currentThread().get
...
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried
URL configURL1 = Thread.currentThread().get ContextCla ssLoader() .getResour ce(new File(DEFAUL_CONFIG_FILE).t oURL().toS tring());
but it still returns NULL,
I added c:\j\ to the classpath and tried
URL configURL1 = Thread.currentThread().get ContextCla ssLoader() .getResour ce("../res ources/pro perties/co nfig.xml") ;
that returned NULL as well.
I tried
configFile = "../resources/properties/c onfig.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
URL configURL1 = Thread.currentThread().get
but it still returns NULL,
I added c:\j\ to the classpath and tried
URL configURL1 = Thread.currentThread().get
that returned NULL as well.
I tried
configFile = "../resources/properties/c
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().get ContextCla ssLoader() .getResour ce("resour ces/proper ties/confi g.xml");
(IE with out the ../)
URL configURL1 = Thread.currentThread().get
(IE with out the ../)
ASKER
I tried
URL configURL1 = Thread.currentThread().get ContextCla ssLoader() .getResour ce("resour ces/proper ties/confi g.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.
URL configURL1 = Thread.currentThread().get
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.
URL configURL1 = Thread.currentThread().get