Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

ClassLoader.getSystemResource Help

Thread view: 
h4hrr - 02 Feb 2006 13:39 GMT
Hi
i am trying to load a property file for logging.. but i am always
getting a

java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException

in the main class, i have:
private static Logger logger = LoggerFactory.create(JDBC.class);

and in LoggerFactory create class for initilization

try {
          URL configFileURL =
ClassLoader.getSystemResource(configFile);
           logManager.readConfiguration(configFileURL.openStream());
       } catch (MalformedURLException e1) {
           e1.printStackTrace();

but its not reading the system resourse and URL is always null, the
same code is working for other projects.. what could be the missing
point..

any help is appreciated
Thomas Hawtin - 02 Feb 2006 20:50 GMT
>            URL configFileURL =
> ClassLoader.getSystemResource(configFile);

> but its not reading the system resourse and URL is always null, the
> same code is working for other projects.. what could be the missing
> point..

Presumably the resource is not present on the classpath.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Ian Pilcher - 02 Feb 2006 21:18 GMT
>>            URL configFileURL =
>> ClassLoader.getSystemResource(configFile);
[quoted text clipped - 4 lines]
>
> Presumably the resource is not present on the classpath.

Or it is, but the OP is specifying it incorrectly.  The documentation
doesn't give much help in this area, but I've found that using a fully
qualified name, *without* a starting slash, works.

For example, if the file I'm after is located at
$CLASSPATH/foo/bar/baz.xml, I'll refer to it as "foo/bar/baz.xml".

HTH

Signature

========================================================================
Ian Pilcher                                        i.pilcher@comcast.net
========================================================================

h4hrr - 02 Feb 2006 23:05 GMT
the file is in the root directory of the project.. and i define it like

private static String configFile = "log.paramters"

still trying to find the cause :-||
Ian Pilcher - 02 Feb 2006 23:48 GMT
> the file is in the root directory of the project.. and i define it like
>
> private static String configFile = "log.paramters"
>
> still trying to find the cause :-||

IIRC, getResource and friends may not work for objects in the root
directory.  Try moving it to a subdirectory.

Signature

========================================================================
Ian Pilcher                                        i.pilcher@comcast.net
========================================================================

Nirav - 03 Feb 2006 09:56 GMT
Try loading it with contextClassLoader, it will load resource from root
directory as well.

Nirav Thaker
Thomas Hawtin - 03 Feb 2006 18:23 GMT
> Try loading it with contextClassLoader, it will load resource from root
> directory as well.

Loading from a Class will ensure that the resource is loaded from a path
appropriate to the class. You probably don't need to get involved with
class-loaders directly yourself.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.