0

I have a properties file: hibernate.properties inside default package. I am trying to read it from a class inside another package: com.somepackage.SomeClass.

In a normal desktop application, the following input stream is working:

InputStream is = getClass().getResourceAsStream("/hibernate.properties");

But with my web app (A maven web application created using Netbeans with JSF 2.2 as dependency)

I tried these alternatives:

Using class:

getClass().getResourceAsStream("/hibernate.properties");

Using external context:

FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/hibernate.properties");

Using context class loader:

Thread.currentThread().getContextClassLoader().getResourceAsStream("/hibernate.properties");

Each of these return null. How do I read the properties file inside the default package?

coolscitist
  • 3,317
  • 8
  • 42
  • 59

1 Answers1

0

I assume you are looking on the wrong location for the file. hibernate.properties is usually not saved in the root of the deployment. Open your .war file and look up the location of hibernate.properties. If you have your application deployed to localhost:8080/app1 you need to call /app1/ to access the contents of your deployment.

Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43