Environment

play.api.Environment
See theEnvironment companion object
case class Environment(rootPath: File, classLoader: ClassLoader, mode: Mode)

The environment for the application.

Captures concerns relating to the classloader and the filesystem for the application.

Value parameters

classLoader

The classloader that all application classes and resources can be loaded from.

mode

The mode of the application.

rootPath

The root path that the application is deployed at.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def asJava: Environment

Attributes

Returns

Returns the Java version for this environment.

def getExistingFile(relativePath: String): Option[File]

Retrieves a file relative to the application root path. This method returns an Option[File], using None if the file was not found.

Retrieves a file relative to the application root path. This method returns an Option[File], using None if the file was not found.

Note that it is up to you to manage the files in the application root path in production. By default, there will be nothing available in the application root path.

For example, to retrieve some deployment specific data file:

val myDataFile = application.getExistingFile("data/data.xml")

Value parameters

relativePath

the relative path of the file to fetch

Attributes

Returns

an existing file

def getFile(relativePath: String): File

Retrieves a file relative to the application root path.

Retrieves a file relative to the application root path.

Note that it is up to you to manage the files in the application root path in production. By default, there will be nothing available in the application root path.

For example, to retrieve some deployment specific data file:

val myDataFile = application.getFile("data/data.xml")

Value parameters

relativePath

relative path of the file to fetch

Attributes

Returns

a file instance; it is not guaranteed that the file exists

def resource(name: String): Option[URL]

Scans the application classloader to retrieve a resource.

Scans the application classloader to retrieve a resource.

The conf directory is included on the classpath, so this may be used to look up resources, relative to the conf directory.

For example, to retrieve the conf/logback.xml configuration file:

val maybeConf = application.resource("logback.xml")

Value parameters

name

the absolute name of the resource (from the classpath root)

Attributes

Returns

the resource URL, if found

def resourceAsStream(name: String): Option[InputStream]

Scans the application classloader to retrieve a resource’s contents as a stream.

Scans the application classloader to retrieve a resource’s contents as a stream.

The conf directory is included on the classpath, so this may be used to look up resources, relative to the conf directory.

For example, to retrieve the conf/logback.xml configuration file:

val maybeConf = application.resourceAsStream("logback.xml")

Value parameters

name

the absolute name of the resource (from the classpath root)

Attributes

Returns

a stream, if found

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product