0

I need to have access to a properties file from within my java web application. So I would normally put this in my classpath somewhere, and load it using getResourceAsStream("my.properties").

I also need to access the same properties file from within javascript. I know I could read this using an XHR if the file exists in the web resources folder, but in this case it does not.

What can I do here? I'm trying to avoid two copies of the file.

Project
- JavaSource
  - MyClass.java
  - my.properties
- WebContent
  - myjavascript.js
StephenH
  • 93
  • 1
  • 5
  • 5
    Leave the properties file where it is and write a Java API that JS would use through AJAX calls to access the file – Stugal May 15 '15 at 13:24

1 Answers1

0

You can write a Java service that turns the properties file into JSON. It's pretty easy to do, and something that I've done in a few projects. You can then just call it by AJAX or referencing it in a script tag.

Community
  • 1
  • 1
Mike Thomsen
  • 36,828
  • 10
  • 60
  • 83