0

I have a properties file in JAR file.

In my web application, I want to access this properties file from the jsp within web application.

I try doing it with the following code, but results in FileNotFoundException

Properties properties = new Properties();
properties.load(new FileInputStream("myfile.properties"));

How can i access the file from JAR which is in my classpath within scriptlets in jsp?

Thanks in advance.

user549757
  • 32,962
  • 4
  • 19
  • 20

2 Answers2

2

Not this way. You can try to get the Input Stream by using 'getResourceAsStream' functionality.

Read about this Here

Hope this helps

Community
  • 1
  • 1
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
0

Yes you can using

InputStream in = this.getClass().getClassLoader().getResourceAsStream("//myfile.properties"); 

Make sure your jar file which has this property file is in classpath.

Rahul Agrawal
  • 8,913
  • 18
  • 47
  • 59