§Anatomy of a Play application
§The Play application layout
The layout of a Play application is standardized to keep things as simple as possible. After the first successful compilation, the project structure looks like this:
app directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources.
There are three packages in the
app directory, one for each component of the MVC architectural pattern:
You can add your own packages, for example, an
Note: in Play, the
viewspackage names are simply conventions that can be changed if needed (such as prefixing everything with
There is also an optional directory called
app/assets for compiled assets such as LESS sources and CoffeeScript sources.
Resources stored in the
public directory are static assets that are served directly by the Web server.
In a newly-created application, the
/publicdirectory is mapped to the
/assetsURL path, but you can easily change that, or even use several directories for your static assets.
conf directory contains the application’s configuration files. There are two main configuration files:
application.confis the main configuration file for the application
routesis the routers’ definition file.
If you need to add configuration options that are specific to your application, it’s a good idea to add more options to the
If a library needs a specific configuration file, it is good to provide it under the
lib directory is optional and contains unmanaged library dependencies, ie. all JAR files you want to manually manage outside the build system. Just drop any JAR files here and they will be added to your application classpath.
Your project’s main build declarations are generally found in
build.sbt at the root of the project.
project directory contains the sbt build definitions:
plugins.sbtdefines sbt plugins used by this project.
build.propertiescontains the sbt version to use to build your app.
target directory contains everything generated by the build system. It can be useful to know what is generated here:
classes/contains all compiled classes (from both Java and Scala sources).
classes_managed/contains only the classes that are managed by the framework (such as the classes generated by the router or the template system). It can be useful to add this class folder as an external class folder in your IDE project.
resource_managed/contains generated resources, typically compiled assets such as LESS CSS and CoffeeScript compilation results.
src_managed/contains generated sources, such as the Scala sources generated by the template system.
web/contains assets processed by sbt-web such as those from the
Generated folders should be ignored by your version control system. Here is the typical
.gitignore file for a Play application:
logs project/project project/target target tmp dist .cache RUNNING_PID
§Default sbt layout
You also have the option of using the default layout used by sbt and Maven. In order to use this layout, you must disable the layout plugin and set up explicit monitoring for twirl templates:
lazy val root: Project = (project in file(".")) .enablePlugins(PlayScala) // Use sbt default layout .disablePlugins(PlayLayoutPlugin)
This will stop Play from overriding the default sbt layout, which looks like this:
Next: Using the Play console
Found an error in this documentation? The source code for this page can be found here. After reading the documentation guidelines, please feel free to contribute a pull request. Have questions or advice to share? Go to our community forums to start a conversation with the community.