0

I'm building a web application using 'Play Framework 2.5' and I have planned to place a custom XML file inside the conf/ directory of the application. This file will contain some information used to populate some meta-tag to help search engines to index my public web pages. The question is how I can open this file (named searchEngines.xml) from a controller's action?

When the file will be open (so I have a stream with it) I can easily read and parse it.

2 Answers2

0

It's pretty straight forward

Source.fromFile("conf/your-file-name.xml")
mavarazy
  • 7,562
  • 1
  • 34
  • 60
  • Ok, thanks. When my project will be finished and I publish my project the command still work again? I have read that, in distribution mode, the conf directory is outside from the classpath. – Andrea Meneghinello Jun 17 '16 at 09:40
  • What is distributed mode? If you are centralizing your application configurations, with a single point of configuration, you'll have to change that path obviously. – mavarazy Jun 19 '16 at 10:39
  • Now, because I'm writing it I execute with the activator run command, but from different guide I read that there is the activator dist command that build an "executable" ready for the production environment – Andrea Meneghinello Jun 19 '16 at 10:56
0

Try using

Play.application.resourceAsStream("your-config-file-name.xml")

as mentioned on this post

Community
  • 1
  • 1
Rjk
  • 1,356
  • 3
  • 15
  • 25