1 | # Using the Play 2.0 console |
---|
2 | |
---|
3 | ## Launching the console |
---|
4 | |
---|
5 | The Play 2.0 console is a development console based on sbt that allows you to manage a Play applicationâs complete development cycle. |
---|
6 | |
---|
7 | To launch the console, enter any existing Play application directory and run the `play` script: |
---|
8 | |
---|
9 | ```bash |
---|
10 | $ cd /path/to/any/application |
---|
11 | $ play |
---|
12 | ``` |
---|
13 | |
---|
14 | [[images/console.png]] |
---|
15 | |
---|
16 | ## Getting help |
---|
17 | |
---|
18 | Use the `help play` command to get basic help about the available commands: |
---|
19 | |
---|
20 | ```bash |
---|
21 | [My first application] $ help play |
---|
22 | ``` |
---|
23 | |
---|
24 | ## Running the server in development mode |
---|
25 | |
---|
26 | To run the current application in development mode, use the `run` command: |
---|
27 | |
---|
28 | ```bash |
---|
29 | [My first application] $ run |
---|
30 | ``` |
---|
31 | |
---|
32 | [[images/consoleRun.png]] |
---|
33 | |
---|
34 | In this mode, the server will be launched with the auto-reload feature enabled, meaning that for each request Play will check your project and recompile required sources. If needed the application will restart automatically. |
---|
35 | |
---|
36 | If there are any compilation errors you will see the result of the compilation directly in your browser: |
---|
37 | |
---|
38 | [[images/errorPage.png]] |
---|
39 | |
---|
40 | To stop the server, type `Crtl+D` key, and you will be returned to the Play console prompt. |
---|
41 | |
---|
42 | ## Compiling |
---|
43 | |
---|
44 | In Play 2.0 you can also compile your application without running the server. Just use the `compile` command: |
---|
45 | |
---|
46 | ```bash |
---|
47 | [My first application] $ compile |
---|
48 | ``` |
---|
49 | |
---|
50 | [[images/consoleCompile.png]] |
---|
51 | |
---|
52 | ## Launch the interactive console |
---|
53 | |
---|
54 | Type `console` to enter the interactive Scala console, which allows you to test your code interactively: |
---|
55 | |
---|
56 | ```bash |
---|
57 | [My first application] $ console |
---|
58 | ``` |
---|
59 | |
---|
60 | [[images/consoleEval.png]] |
---|
61 | |
---|
62 | ## Debugging |
---|
63 | |
---|
64 | You can ask Play to start a **JPDA** debug port when starting the console. You can then connect using Java debugger. Use the `play debug` command to do that: |
---|
65 | |
---|
66 | ``` |
---|
67 | $ play debug |
---|
68 | ``` |
---|
69 | |
---|
70 | When a JPDA port is available, the JVM will log this line during boot: |
---|
71 | |
---|
72 | ``` |
---|
73 | Listening for transport dt_socket at address: 9999 |
---|
74 | ``` |
---|
75 | |
---|
76 | > **Note:** Using `play debug` the JPDA socket will be opened on port `9999`. You can also set the `JPDA_PORT` environment variable yourself using `set JPDA_PORT=1234`. |
---|
77 | |
---|
78 | ## Using sbt features |
---|
79 | |
---|
80 | The Play console is just a normal sbt console, so you can use sbt features such as **triggered execution**. |
---|
81 | |
---|
82 | For example, using `~ compile` |
---|
83 | |
---|
84 | ```bash |
---|
85 | [My first application] $ ~ compile |
---|
86 | ``` |
---|
87 | |
---|
88 | The compilation will be triggered each time you change a source file. |
---|
89 | |
---|
90 | If you are using `~ run` |
---|
91 | |
---|
92 | ```bash |
---|
93 | [My first application] $ ~ run |
---|
94 | ``` |
---|
95 | |
---|
96 | The triggered compilation will be enabled while a development server is running. |
---|
97 | |
---|
98 | You can also do the same for `~ test`, to continuously test your project each time you modify a source file: |
---|
99 | |
---|
100 | ```bash |
---|
101 | [My first application] $ ~ test |
---|
102 | ``` |
---|
103 | |
---|
104 | ## Using the play commands directly |
---|
105 | |
---|
106 | You can also run commands directly without entering the Play console. For example, enter `play run`: |
---|
107 | |
---|
108 | ```bash |
---|
109 | $ play run |
---|
110 | [info] Loading project definition from myFirstApp/project |
---|
111 | [info] Set current project to My first application |
---|
112 | |
---|
113 | --- (Running the application from SBT, auto-reloading is enabled) --- |
---|
114 | |
---|
115 | [info] play - Listening for HTTP on port 9000... |
---|
116 | |
---|
117 | (Server started, use Ctrl+D to stop and go back to the console...) |
---|
118 | ``` |
---|
119 | |
---|
120 | The application starts directly. When you quit the server using `Ctrl+D`, you will come back to your OS prompt. |
---|
121 | |
---|
122 | ## Force clean |
---|
123 | |
---|
124 | If something goes wrong and you think that the sbt cache is corrupted, use the `clean-all` command for your OS command line to clean all generated directories. |
---|
125 | |
---|
126 | ``` |
---|
127 | $ play clean-all |
---|
128 | ``` |
---|
129 | |
---|
130 | > **Next:** [[Setting-up your preferred IDE | IDE]] |
---|