1 | # Anatomy of a Play 2.0 application |
---|
2 | |
---|
3 | ## The standard application layout |
---|
4 | |
---|
5 | The layout of a Play application is standardized to keep things as simple as possible. A standard Play application looks like this: |
---|
6 | |
---|
7 | ``` |
---|
8 | app â Application sources |
---|
9 | â assets â Compiled asset sources |
---|
10 | â stylesheets â Typically LESS CSS sources |
---|
11 | â javascripts â Typically CoffeeScript sources |
---|
12 | â controllers â Application controllers |
---|
13 | â models â Application business layer |
---|
14 | â views â Templates |
---|
15 | conf â Configurations files and other non-compiled resources (on classpath) |
---|
16 | â application.conf â Main configuration file |
---|
17 | â routes â Routes definition |
---|
18 | public â Public assets |
---|
19 | â stylesheets â CSS files |
---|
20 | â javascripts â Javascript files |
---|
21 | â images â Image files |
---|
22 | project â sbt configuration files |
---|
23 | â build.properties â Marker for sbt project |
---|
24 | â Build.scala â Application build script |
---|
25 | â plugins.sbt â sbt plugins |
---|
26 | lib â Unmanaged libraries dependencies |
---|
27 | logs â Standard logs folder |
---|
28 | â application.log â Default log file |
---|
29 | target â Generated stuff |
---|
30 | â scala-2.9.1 |
---|
31 | â cache |
---|
32 | â classes â Compiled class files |
---|
33 | â classes_managed â Managed class files (templates, ...) |
---|
34 | â resource_managed â Managed resources (less, ...) |
---|
35 | â src_managed â Generated sources (templates, ...) |
---|
36 | test â source folder for unit or functional tests |
---|
37 | ``` |
---|
38 | |
---|
39 | ## The app/ directory |
---|
40 | |
---|
41 | The `app` directory contains all executable artifacts: Java and Scala source code, templates and compiled assetsâ sources. |
---|
42 | |
---|
43 | There are three standard packages in the `app` directory, one for each component of the MVC architectural pattern: |
---|
44 | |
---|
45 | - `app/controllers` |
---|
46 | - `app/models` |
---|
47 | - `app/views` |
---|
48 | |
---|
49 | You can of course add your own packages, for example an `app/utils` package. |
---|
50 | |
---|
51 | > Note that in Play 2.0, the controllers, models and views package name conventions are now just that and can be changed if needed (such as prefixing everything with `com.yourcompany`). |
---|
52 | |
---|
53 | There is also an optional directory called `app/assets` for compiled assets such as [[LESS sources | http://lesscss.org/]] and [[CoffeeScript sources | http://jashkenas.github.com/coffee-script/]]. |
---|
54 | |
---|
55 | ## The public/ directory |
---|
56 | |
---|
57 | Resources stored in the `public` directory are static assets that are served directly by the Web server. |
---|
58 | |
---|
59 | This directory is split into three standard sub-directories for images, CSS stylesheets and JavaScript files. You should organize your static assets like this to keep all Play applications consistent. |
---|
60 | |
---|
61 | > In a newly-created application, the `/public` directory is mapped to the `/assets` URL path, but you can easily change that, or even use several directories for your static assets. |
---|
62 | |
---|
63 | ## The conf/ directory |
---|
64 | |
---|
65 | The `conf` directory contains the applicationâs configuration files. There are two main configuration files: |
---|
66 | |
---|
67 | - `application.conf`, the main configuration file for the application, which contains standard configuration parameters |
---|
68 | - `routes`, the routes definition file. |
---|
69 | |
---|
70 | If you need to add configuration options that are specific to your application, itâs a good idea to add more options to the `application.conf` file. |
---|
71 | |
---|
72 | If a library needs a specific configuration file, try to file it under the `conf` directory. |
---|
73 | |
---|
74 | ## The lib/ directory |
---|
75 | |
---|
76 | 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. |
---|
77 | |
---|
78 | ## The project/ directory |
---|
79 | |
---|
80 | The `project` directory contains the sbt build definitions: |
---|
81 | |
---|
82 | - `plugins.sbt` defines sbt plugins used by this project |
---|
83 | - `Build.scala` defines your application build script. |
---|
84 | |
---|
85 | ## The target/ directory |
---|
86 | |
---|
87 | The `target` directory contains everything generated by the build system. It can be useful to know what is generated here. |
---|
88 | |
---|
89 | - `classes/` contains all compiled classes (from both Java and Scala sources). |
---|
90 | - `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. |
---|
91 | - `resource_managed/` contains generated resources, typically compiled assets such as LESS CSS and CoffeeScript compilation results. |
---|
92 | - `src_managed/` contains generated sources, such as the Scala sources generated by the template system. |
---|
93 | |
---|
94 | ## Typical .gitignore file |
---|
95 | |
---|
96 | Generated folders should be ignored by your version control system. Here is the typical `.gitignore` file for a Play application: |
---|
97 | |
---|
98 | ```txt |
---|
99 | logs |
---|
100 | project/project |
---|
101 | project/target |
---|
102 | target |
---|
103 | tmp |
---|
104 | ``` |
---|
105 | |
---|
106 | > **Next:** [[Using the Play 2.0 console | PlayConsole ]] |
---|