Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put resources?

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 
    // ...
}
like image 574
marioosh Avatar asked Dec 21 '12 11:12

marioosh


1 Answers

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"
      ...
  )
like image 167
ndeverge Avatar answered Jan 03 '23 05:01

ndeverge