getResourceAsStream not loading resource

Posted by Michal Gorecki on Stack Overflow See other posts from Stack Overflow or by Michal Gorecki
Published on 2010-03-22T17:05:08Z Indexed on 2010/03/22 17:11 UTC
Read the original article Hit count: 225

Filed under:

The project that I am currently working on utilizes an old application contained within a .jar file. One of the responsibilities of this application is that it updates the database when changes to the configuration files are made. Every time I try to run this file (which is a simple Ant Task extension), I get an exception thrown early in the process. I decompiled the Java file responsible, and found that the exception being thrown happens here. I do not know what the issue is, as "hibernate.cfg.xml" is contained within the same .jar file as the .class throwing the exception.

ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream in = loader.getResourceAsStream("hibernate.cfg.xml");
if (in == null) {
  throw new RuntimeException("Couldn't find built in hibernate config");
}

If anyone has any ideas, even pointing me in the right direction, I would be grateful.

Of course, any solution will have to be external, as the client already has this build of the program in production use.

© Stack Overflow or respective owner

Related posts about java