I'm storing files to a folder in a play! project and I have a question about paths. My solution is working, but I think the solution is sub optimal.
My current solution:
public static String getStoragePath(){
String pubDir = Play.application().configuration().getString("pathToFiles");
if(Play.isProd()){
String prodDir = Play.application().configuration().getString("productionPath");
//prodDir variable is "target/scala-2.9.1/classes"
return Play.application().path().getAbsolutePath() + "/" + prodDir + "/" + pubDir;
}else{
return Play.application().path().getAbsolutePath() + "/" + pubDir;
}
}
My question:
I do it like this because the paths are different when running "play run" and "play start". Is there a way to avoid using this if-block? I dont want to be dependent on the productionPath string in my configuration file.
Using the conf file is the way to do it. Just use a different conf file for your production enviroment and you will not need to have a bunch of if(isProd...) checks in your code.
Play 2 has ability to use alternative/extending configuration files as described in documentation (Specifying alternative configuration file section). Additionally you can create simple bash script (or .bat file in Windows) to start the application in desired mode without need to specify alternative file each time.