Package play
Class Environment
- Object
-
- play.Environment
-
public class Environment extends Object
The environment for the application.Captures concerns relating to the classloader and the filesystem for the application.
-
-
Constructor Summary
Constructors Constructor Description Environment(File rootPath)
Environment(File rootPath, ClassLoader classLoader, Mode mode)
Environment(File rootPath, Mode mode)
Environment(play.api.Environment environment)
Environment(Mode mode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description play.api.Environment
asScala()
The underlying Scala API Environment object that this Environment wraps.ClassLoader
classLoader()
The classloader that all application classes and resources can be loaded from.Optional<File>
getExistingFile(String relativePath)
Retrieves a file relative to the application root path.File
getFile(String relativePath)
Retrieves a file relative to the application root path.boolean
isDev()
Returns `true` if the application is `DEV` mode.boolean
isProd()
Returns `true` if the application is `PROD` mode.boolean
isTest()
Returns `true` if the application is `TEST` mode.Mode
mode()
The mode of the application.URL
resource(String relativePath)
Retrieves a resource from the classpath.InputStream
resourceAsStream(String relativePath)
Retrieves a resource stream from the classpath.File
rootPath()
The root path that the application is deployed at.static Environment
simple()
A simple environment.
-
-
-
Constructor Detail
-
Environment
public Environment(play.api.Environment environment)
-
Environment
public Environment(File rootPath, ClassLoader classLoader, Mode mode)
-
Environment
public Environment(File rootPath)
-
Environment
public Environment(Mode mode)
-
-
Method Detail
-
rootPath
public File rootPath()
The root path that the application is deployed at.- Returns:
- the path
-
classLoader
public ClassLoader classLoader()
The classloader that all application classes and resources can be loaded from.- Returns:
- the class loader
-
mode
public Mode mode()
The mode of the application.- Returns:
- the mode
-
isDev
public boolean isDev()
Returns `true` if the application is `DEV` mode.- Returns:
- `true` if the application is `DEV` mode.
-
isProd
public boolean isProd()
Returns `true` if the application is `PROD` mode.- Returns:
- `true` if the application is `PROD` mode.
-
isTest
public boolean isTest()
Returns `true` if the application is `TEST` mode.- Returns:
- `true` if the application is `TEST` mode.
-
getFile
public File getFile(String relativePath)
Retrieves a file relative to the application root path.- Parameters:
relativePath
- relative path of the file to fetch- Returns:
- a file instance - it is not guaranteed that the file exists
-
getExistingFile
public Optional<File> getExistingFile(String relativePath)
Retrieves a file relative to the application root path. This method returns an Optional, using empty if the file was not found.- Parameters:
relativePath
- relative path of the file to fetch- Returns:
- an existing file
-
resource
public URL resource(String relativePath)
Retrieves a resource from the classpath.- Parameters:
relativePath
- relative path of the resource to fetch- Returns:
- URL to the resource (may be null)
-
resourceAsStream
public InputStream resourceAsStream(String relativePath)
Retrieves a resource stream from the classpath.- Parameters:
relativePath
- relative path of the resource to fetch- Returns:
- InputStream to the resource (may be null)
-
simple
public static Environment simple()
A simple environment.Uses the same classloader that the environment classloader is defined in, the current working directory as the path and test mode.
- Returns:
- the environment
-
asScala
public play.api.Environment asScala()
The underlying Scala API Environment object that this Environment wraps.- Returns:
- the environment
- See Also:
Environment
-
-