How to get the app root path in play2?
Asked Answered
B

2

5

In play1, we can get the app path by:

Play.applicationPath

How to do the same in Play2?

Berg answered 15/2, 2012 at 14:0 Comment(0)
C
7

With the Scala API, you can do it like this to get a java.io.File to the app:

import play.api.Play.current
Play.application.path

In Java:

import play.Play;
Play.application().path();
Claim answered 15/2, 2012 at 14:57 Comment(3)
for those wondering, using Java it's File root=Play.application().path();Tutty
I get a "cannot find symbol" if I try to use Play.application().path() in Java. What do you import?Pritchett
In scala play 2.2, use the same import with current.path insteadLeckie
P
2

For Play 2.5.x it should be like this. I keep the stuffs not related to the question. However, should be handy for other things.

package io

import javax.inject.Inject
import com.google.inject.Singleton
import play.Application
import play.api.Environment

@Singleton
class File @Inject()(environment: Environment, application: Application) {
    val home: java.io.File = application.path()
}
Puisne answered 28/3, 2017 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.