I need to add some properties file to my application. I have added this file to controller
directory, but can't load them (no in classpath ?) - InputStream
is null. Where to put this file to can be accessed ?
public class Application extends Controller {
static {
try {
Properties p = new Properties();
InputStream in = Application.class.getClassLoader().getResourceAsStream("accounts.properties");
if(in != null) {
p.load(in);
in.close();
} else {
error("null inputstream");
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Actions below
// ...
}
You have to put it in the conf
folder of your Play app.
You can also use subfolder in the conf
directory.
For instance:
conf/foo/bar.txt
can be accessed using:
InputStream in = MyClass.class. getResourceAsStream("/foo/bar.txt")
You can also add a custom resources directory in your app, by updating your project/Build.scala
file and adding:
val main = play.Project(appName, appVersion, appDependencies).settings(
...
resourceDirectory in Compile <<= baseDirectory / "myresources"
...
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With