Skip to content
Newer
Older
100644 720 lines (442 sloc) 22.6 KB
6705ab5 @jamesward doc updates
authored May 2, 2012
1 # Welcome to the Play2torial for Java!
2 ====================================
3
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
4 This tutorial will help teach you how to build Java web applications with Play Framework 2.3.
6705ab5 @jamesward doc updates
authored May 2, 2012
5
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
6 Before you get started you will need to install [git](http://git-scm.com/) and [Play 2.3](https://www.playframework.com/documentation/2.3.x/Installing). You will complete this by installing the Typesafe Activator tool.
6705ab5 @jamesward doc updates
authored May 2, 2012
7
8
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
9 Test that the `activator` command works by running:
6705ab5 @jamesward doc updates
authored May 2, 2012
10
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
11 activator -help
6705ab5 @jamesward doc updates
authored May 2, 2012
12
13
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
14 You should see text displaying optional commands for the activator tool. If you do not, repeat the above process and make sure you are downloading the most recent version of Play (2.3.7).
6705ab5 @jamesward doc updates
authored May 2, 2012
15
16
17 Alright! You are ready to go!
18
19
fe93d75 @jamesward updated tutorial
authored May 7, 2012
20
ce361a8 @jamesward fix titles
authored May 8, 2012
21 Create a Play App
22 -----------------
6705ab5 @jamesward doc updates
authored May 2, 2012
23
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
24 Create a new Play 2.3 application named "play2torial" by running:
6705ab5 @jamesward doc updates
authored May 2, 2012
25
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
26 activator new play2torial
6705ab5 @jamesward doc updates
authored May 2, 2012
27
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
28 When prompted select option 5 `play-java` to create a Java application.
6705ab5 @jamesward doc updates
authored May 2, 2012
29
3b6c289 @jamesward cleanup
authored May 7, 2012
30
6705ab5 @jamesward doc updates
authored May 2, 2012
31 In the newly created `play2torial` directory create a new git repository by running:
32
33 git init
34
3b6c289 @jamesward cleanup
authored May 7, 2012
35
6705ab5 @jamesward doc updates
authored May 2, 2012
36 Add the files to the git repo and commit them:
cc2117c @jamesward more updates for play 2.3
authored Apr 1, 2015
37
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
38 ```sh
39 git add .
40 git commit -m init
41 ```
3b6c289 @jamesward cleanup
authored May 7, 2012
42
6705ab5 @jamesward doc updates
authored May 2, 2012
43 Throughout this tutorial you will be able to check your progress against the official tutorial. To do this add the official tutorial as a new git remote named `upstream` by running:
44
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
45 git remote add upstream https://github.com/jamesward/play2torial.git
6705ab5 @jamesward doc updates
authored May 2, 2012
46
47
3b6c289 @jamesward cleanup
authored May 7, 2012
48 Fetch the remote repository:
49
50 git fetch upstream
51
52
53 Now validate that your local project is correct by running:
6705ab5 @jamesward doc updates
authored May 2, 2012
54
3b6c289 @jamesward cleanup
authored May 7, 2012
55 git diff upstream/java-new_project
6705ab5 @jamesward doc updates
authored May 2, 2012
56
3b6c289 @jamesward cleanup
authored May 7, 2012
57 Note: The `application.secret` config value will be different and that is fine. Also sometimes git will tell you something is different even though it looks the same. This will likely be due to differences in indentation and newlines. You can ignore these differences.
6705ab5 @jamesward doc updates
authored May 2, 2012
58
59
fe93d75 @jamesward updated tutorial
authored May 7, 2012
60
ce361a8 @jamesward fix titles
authored May 8, 2012
61 Set up an IDE
62 -------------
6705ab5 @jamesward doc updates
authored May 2, 2012
63
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
64 Before we take a tour of the app you can optionally generate project files for Eclipse. This is highly recommended.
6705ab5 @jamesward doc updates
authored May 2, 2012
65
66
67 For Eclipse run:
68
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
69 activator eclipse
6705ab5 @jamesward doc updates
authored May 2, 2012
70
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
71 For IntelliJ, install the Scala IntelliJ Plugin and then open the project's `build.sbt` file from the `File > Open...` dialog.
6705ab5 @jamesward doc updates
authored May 2, 2012
72
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
73 _Read more about [IDE's](https://www.playframework.com/documentation/2.3.x/IDE)_
6705ab5 @jamesward doc updates
authored May 2, 2012
74
fe93d75 @jamesward updated tutorial
authored May 7, 2012
75
ce361a8 @jamesward fix titles
authored May 8, 2012
76 Start the Play Server
77 ---------------------
6705ab5 @jamesward doc updates
authored May 2, 2012
78
79 Now start the Play app by running:
80
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
81 activator ~run
6705ab5 @jamesward doc updates
authored May 2, 2012
82
1c3f1f3 @jamesward fixes
authored May 7, 2012
83 Open the following URL in your browser to verify the app is working:
3b6c289 @jamesward cleanup
authored May 7, 2012
84 [http://localhost:9000/](http://localhost:9000/)
6705ab5 @jamesward doc updates
authored May 2, 2012
85
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
86 _Read more about the [Play Console](https://www.playframework.com/documentation/2.3.x/PlayConsole)_
fe93d75 @jamesward updated tutorial
authored May 7, 2012
87
6705ab5 @jamesward doc updates
authored May 2, 2012
88 Routes
89 ------
90
91 Play routes HTTP requests to a controller using the routes defined in the `conf/routes` file. The routes file maps HTTP verbs and URL patterns to controller methods. The route that matched the request you just made was defined in the "routes" file with:
92
93 GET / controllers.Application.index()
94
95
96 That means that when a HTTP GET request for the URL `/` comes in, it will be routed to the method named `index` on the `controllers.Application` class.
97
3b6c289 @jamesward cleanup
authored May 7, 2012
98 Add a new route to handle GET requests to `/foo` with a call to `controllers.Application.index()` by adding the following line to the `conf/routes` file:
6705ab5 @jamesward doc updates
authored May 2, 2012
99
100 GET /foo controllers.Application.index()
101
102
1c3f1f3 @jamesward fixes
authored May 7, 2012
103 Now try to open the following URL in your browser:
3b6c289 @jamesward cleanup
authored May 7, 2012
104 [http://localhost:9000/foo](http://localhost:9000/foo)
6705ab5 @jamesward doc updates
authored May 2, 2012
105
106 You should see the same welcome message as your did when you made the request to the `/` URL.
107
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
108 _Read more about [Routing](https://www.playframework.com/documentation/2.3.x/JavaRouting)_
21d99d5 @matsev Added links to the reference docs.
matsev authored Oct 23, 2012
109
6705ab5 @jamesward doc updates
authored May 2, 2012
110 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
111
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
112 ```sh
113 git commit -am "added new route"
114 git diff upstream/java-foo_route
115 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
116
fe93d75 @jamesward updated tutorial
authored May 7, 2012
117
6705ab5 @jamesward doc updates
authored May 2, 2012
118 Test a Route
119 ------------
1c3f1f3 @jamesward fixes
authored May 7, 2012
120
6705ab5 @jamesward doc updates
authored May 2, 2012
121 Now that you have a new route for `/foo` lets create a test for that route. Now create a new file `test/FooTest.java` file containing:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
122
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
123 ```java
124 import org.junit.Test;
125 import play.mvc.Result;
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
126 import play.test.Helpers;
127 import play.test.WithApplication;
128
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
129 import static play.test.Helpers.*;
130 import static org.fest.assertions.Assertions.*;
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
131
132 public class FooTest extends WithApplication {
133
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
134 @Test
135 public void testFooRoute() {
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
136 Result result = route(fakeRequest(GET, "/foo"));
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
137 assertThat(result).isNotNull();
6705ab5 @jamesward doc updates
authored May 2, 2012
138 }
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
139
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
140 }
141 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
142
143 That simple test will simulate a call to `/foo` and validate that the result was not null. Run the test (you can keep the Play server running in another window):
144
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
145 activator test
6705ab5 @jamesward doc updates
authored May 2, 2012
146
147
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
148 You should see something similiar to:
6705ab5 @jamesward doc updates
authored May 2, 2012
149
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
150 [info] Passed: Total 4, Failed 0, Errors 0, Passed 4
6705ab5 @jamesward doc updates
authored May 2, 2012
151
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
152 _Read more about [Testing Routes](https://www.playframework.com/documentation/2.3.x/JavaFunctionalTest)_
6705ab5 @jamesward doc updates
authored May 2, 2012
153
154 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
155
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
156 ```sh
157 git add test
158 git commit -m "added test for foo route"
159 git diff upstream/java-test_route
160 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
161
fe93d75 @jamesward updated tutorial
authored May 7, 2012
162
6705ab5 @jamesward doc updates
authored May 2, 2012
163 Update a Controller
164 -------------------
165
166 The `app` directory is the main source for a Play app. In that directory there is a directory named `controllers` containing a file named `Application.java` which is the `controllers.Application` class.
167
168 The `index()` method body looks like:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
169
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
170 ```java
171 return ok(index.render("Your new application is ready."));
172 ```
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
173
1c3f1f3 @jamesward fixes
authored May 7, 2012
174 Edit the `Application.java` file and change the `Your new application is ready.` string to `hello, world`. Save the file and then reload the following URL in your browser:
3b6c289 @jamesward cleanup
authored May 7, 2012
175 [http://localhost:9000/](http://localhost:9000/)
6705ab5 @jamesward doc updates
authored May 2, 2012
176
177
178 Notice that the header at the top of the page now reads `hello, world`. Play recompiled the Java controller behind the scenes. If you had made a change that could not be compiled you would see the compile error in your browser and in your console.
179
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
180 This change will break two of the existing tests so change the `Your new application is ready.` string to `hello, world` in the `test/ApplicationTest.java` and `test/IntegrationTest.java` files.
181
182 To verify the tests pass, run:
183
184 activator test
185
6705ab5 @jamesward doc updates
authored May 2, 2012
186 Commit and verify that your changes:
187
188 git commit -am "updated controller"
3b6c289 @jamesward cleanup
authored May 7, 2012
189 git diff upstream/java-hello_controller
6705ab5 @jamesward doc updates
authored May 2, 2012
190
191
fe93d75 @jamesward updated tutorial
authored May 7, 2012
192
6705ab5 @jamesward doc updates
authored May 2, 2012
193 Test a Controller
194 -----------------
195
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
196 You can do tests against a controller by simply creating a new JUnit Test. Add a new test method to the `test/ApplicationTest.java` file:
197
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
198 ```java
199 @Test
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
200 public void testIndex() {
201 Result result = controllers.Application.index();
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
202 assertThat(status(result)).isEqualTo(OK);
203 assertThat(contentType(result)).isEqualTo("text/html");
204 assertThat(charset(result)).isEqualTo("utf-8");
205 assertThat(contentAsString(result)).contains("hello, world");
6705ab5 @jamesward doc updates
authored May 2, 2012
206 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
207 ```
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
208
6705ab5 @jamesward doc updates
authored May 2, 2012
209 This simulates a request to the `Application.index()` controller method and verifies that the response is what we expect. Run the test:
210
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
211 activator test
6705ab5 @jamesward doc updates
authored May 2, 2012
212
213
214 You should see something like:
215
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
216 [info] Passed: Total 5, Failed 0, Errors 0, Passed 5
6705ab5 @jamesward doc updates
authored May 2, 2012
217
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
218 _Read more about [Testing Controllers](https://www.playframework.com/documentation/2.3.x/JavaFunctionalTest)_
6705ab5 @jamesward doc updates
authored May 2, 2012
219
220 Commit and verify that your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
221
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
222 ```sh
223 git add test/ApplicationTest.java
224 git commit -am "added Application controller test"
225 git diff upstream/java-test_controller
226 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
227
fe93d75 @jamesward updated tutorial
authored May 7, 2012
228
6705ab5 @jamesward doc updates
authored May 2, 2012
229 Update a View
230 -------------
231
232 Play uses Scala for server-side templating. The `Application` controller renders the `views.html.index` template which is compiled from the `app/views/index.scala.html` file. The `index` template takes a String parameter:
233
234 @(message: String)
235
236
237 Then the `index` template uses the `main` template (from `app/views/main.scala.html`) to get a base HTML page:
238
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
239 @main("Welcome to Play") {
6705ab5 @jamesward doc updates
authored May 2, 2012
240
241
242 The main template is passed a String parameter for the page title and a Html parameter for the body of the page. The body of the page is the Play welcome message which comes from:
243
244 @play20.welcome(message, style = "Java")
245
246
247 Change the Play welcome message to uppercase:
248
249 @play20.welcome(message.toUpperCase, style = "Java")
250
1c3f1f3 @jamesward fixes
authored May 7, 2012
251 View your changes in the browser:
3b6c289 @jamesward cleanup
authored May 7, 2012
252 [http://localhost:9000/](http://localhost:9000/)
6705ab5 @jamesward doc updates
authored May 2, 2012
253
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
254 Because the `test/ApplicationTest.java` and `test/IntegrationTest.java` tests use this updated template, update the tests to account for the upper cased string by changing all `hello, world` strings to `HELLO, WORLD`.
6705ab5 @jamesward doc updates
authored May 2, 2012
255
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
256 As you can see, the `test/ApplicationTest.java` file tests the server-side template directly:
6705ab5 @jamesward doc updates
authored May 2, 2012
257
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
258 ```java
259 @Test
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
260 public void renderTemplate() {
261 Content html = views.html.index.render("HELLO, WORLD");
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
262 assertThat(contentType(html)).isEqualTo("text/html");
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
263 assertThat(contentAsString(html)).contains("HELLO, WORLD");
6705ab5 @jamesward doc updates
authored May 2, 2012
264 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
265 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
266
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
267 The `test/IntegrationTest.java` does an integration test by starting a Play server and using [HtmlUnit](http://htmlunit.sourceforge.net/) to make a headless browser request to the server, thus testing the routes, controller, and views:
6705ab5 @jamesward doc updates
authored May 2, 2012
268
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
269 ```java
270 @Test
271 public void test() {
272 running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
273 public void invoke(TestBrowser browser) {
274 browser.goTo("http://localhost:3333");
275 assertThat(browser.pageSource()).contains("HELLO, WORLD");
276 }
277 });
278 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
279 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
280
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
281 Run the tests and verify they all pass:
fe93d75 @jamesward updated tutorial
authored May 7, 2012
282
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
283 activator test
6705ab5 @jamesward doc updates
authored May 2, 2012
284
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
285 _Read more about [Templating](https://www.playframework.com/documentation/2.3.x/JavaTemplates) and [Template Use Cases](https://www.playframework.com/documentation/2.3.x/JavaTemplateUseCases)_
1c3f1f3 @jamesward fixes
authored May 7, 2012
286
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
287 Commit and verify that your changes:
6705ab5 @jamesward doc updates
authored May 2, 2012
288
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
289 ```sh
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
290 git commit -am "change the view"
291 git diff upstream/java-hello_view
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
292 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
293
294
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
295 Deploy your app on the Cloud with Heroku
296 ----------------------------------------
6705ab5 @jamesward doc updates
authored May 2, 2012
297
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
298 Deploying your Play app on the cloud is easy with Heroku!
6705ab5 @jamesward doc updates
authored May 2, 2012
299
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
300 1. [Install the Heroku Toolbelt](http://toolbelt.heroku.com)
301 2. [Signup for a free Heroku account](http://heroku.com/signup)
302 3. Login to Heroku from the command line:
6705ab5 @jamesward doc updates
authored May 2, 2012
303
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
304 heroku login
6705ab5 @jamesward doc updates
authored May 2, 2012
305
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
306 4. Provision a new application on Heroku:
6705ab5 @jamesward doc updates
authored May 2, 2012
307
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
308 heroku create
6705ab5 @jamesward doc updates
authored May 2, 2012
309
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
310 5. Push the application to Heroku:
6705ab5 @jamesward doc updates
authored May 2, 2012
311
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
312 git push heroku master
1c3f1f3 @jamesward fixes
authored May 7, 2012
313
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
314 Heroku will build the app with sbt and then run it on a [dyno](https://devcenter.heroku.com/articles/dynos).
6705ab5 @jamesward doc updates
authored May 2, 2012
315
316 Open the application, now running on the cloud, in your browser:
317
318 heroku open
319
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
320 The page should say `HELLO, WORLD` but will look different from what you see locally since the `play20.welcome` template our app is using, displays different stuff depending on whether you are running in `DEV` or `PROD` mode. To run locally in `PROD` mode, stop the `activator ~run` process and instead run `activator start`. This mode does not do any auto-reloading.
6705ab5 @jamesward doc updates
authored May 2, 2012
321
322
323 Create a Model
324 --------------
325
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
326 By default, Play 2.3 with Java uses [Ebean](http://www.avaje.org/) for RDBMS persistence. To setup a data source, edit the `conf/application.conf` file and uncomment these lines:
327
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
328 ```properties
329 db.default.driver=org.h2.Driver
330 db.default.url="jdbc:h2:mem:play"
6705ab5 @jamesward doc updates
authored May 2, 2012
331
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
332 ebean.default="models.*"
333 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
334
335 This will use an in-memory database for a data source named "default".
336
337 Create a new Java class to hold `Task` objects in a package named `models` by creating a new `app/models/Task.java` file containing:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
338
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
339 ```java
340 package models;
6705ab5 @jamesward doc updates
authored May 2, 2012
341
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
342 import play.db.ebean.Model;
6705ab5 @jamesward doc updates
authored May 2, 2012
343
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
344 import javax.persistence.Entity;
345 import javax.persistence.Id;
6705ab5 @jamesward doc updates
authored May 2, 2012
346
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
347 @Entity
348 public class Task extends Model {
6705ab5 @jamesward doc updates
authored May 2, 2012
349
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
350 @Id
351 public String id;
6705ab5 @jamesward doc updates
authored May 2, 2012
352
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
353 public String contents;
6705ab5 @jamesward doc updates
authored May 2, 2012
354
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
355 }
356 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
357
358 Create a test for your model by creating a new `test/TaskTest.java` file containing:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
359
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
360 ```java
361 import org.junit.Test;
6705ab5 @jamesward doc updates
authored May 2, 2012
362
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
363 import static play.test.Helpers.fakeApplication;
364 import static play.test.Helpers.running;
6705ab5 @jamesward doc updates
authored May 2, 2012
365
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
366 import static org.fest.assertions.Assertions.assertThat;
6705ab5 @jamesward doc updates
authored May 2, 2012
367
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
368 import models.Task;
6705ab5 @jamesward doc updates
authored May 2, 2012
369
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
370 public class TaskTest {
6705ab5 @jamesward doc updates
authored May 2, 2012
371
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
372 @Test
373 public void create() {
374 running(fakeApplication(), new Runnable() {
375 public void run() {
376 Task task = new Task();
377 task.contents = "Write a test";
378 task.save();
379 assertThat(task.id).isNotNull();
380 }
381 });
6705ab5 @jamesward doc updates
authored May 2, 2012
382 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
383
384 }
385 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
386
387 Run the tests and make sure all four pass:
388
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
389 activator test
6705ab5 @jamesward doc updates
authored May 2, 2012
390
391
fe93d75 @jamesward updated tutorial
authored May 7, 2012
392 Ebean will automatically create a new database evolution script for you in a file named `conf/evolutions/default/1.sql`.
6705ab5 @jamesward doc updates
authored May 2, 2012
393
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
394 _Read more about [EBean ORM Models](https://www.playframework.com/documentation/2.3.x/JavaEbean)_
6705ab5 @jamesward doc updates
authored May 2, 2012
395
396 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
397
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
398 ```sh
399 git add conf/evolutions app/models/Task.java test/TaskTest.java
400 git commit -am "added Task model, in-memory database config, and test"
401 git diff upstream/java-task_model
402 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
403
404
405 Create UI for Adding Tasks
406 --------------------------
407
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
408 Start by adding a new method to the `app/controllers/Application.java` file that will map request parameters to a `Task` object, save it, and then redirect to the `index()` page.
6705ab5 @jamesward doc updates
authored May 2, 2012
409
410 Now add a new method named `addTask`:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
411
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
412 ```java
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
413 public static Result addTask() {
414 play.data.Form<models.Task> form = play.data.Form.form(models.Task.class).bindFromRequest();
415 models.Task task = form.get();
416 task.save();
417 return redirect(routes.Application.index());
418 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
419 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
420
b8c3f68 @jamesward updates
authored May 7, 2012
421 Now add a new route to the `conf/routes` file that will handle `POST` requests to `/task` and handle the request with the `Application.addTask()` method:
6705ab5 @jamesward doc updates
authored May 2, 2012
422
fe93d75 @jamesward updated tutorial
authored May 7, 2012
423 POST /task controllers.Application.addTask()
6705ab5 @jamesward doc updates
authored May 2, 2012
424
425
426 Now create a form in the `app/views/index.scala.html` template for adding new `Tasks`. Replace the `@play20.welcome` line with:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
427
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
428 ```html
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
429 @message.toUpperCase
430
431 @helper.form(action = routes.Application.addTask()) {
432 <input name="contents"/>
433 <input type="submit"/>
434 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
435 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
436
1c3f1f3 @jamesward fixes
authored May 7, 2012
437 Test out the new UI by loading the app in your browser:
3b6c289 @jamesward cleanup
authored May 7, 2012
438 [http://localhost:9000/](http://localhost:9000/)
6705ab5 @jamesward doc updates
authored May 2, 2012
439
3b6c289 @jamesward cleanup
authored May 7, 2012
440 You will be prompted to run the database evolutions. Just click the `Apply this script now!` button.
6705ab5 @jamesward doc updates
authored May 2, 2012
441
442 Add a new `Task` and the browser should refresh the index page.
443
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
444 _Read more about [Forms](https://www.playframework.com/documentation/2.3.x/JavaForms) and [Templates](https://www.playframework.com/documentation/2.3.x/JavaFormHelpers)_
21d99d5 @matsev Added links to the reference docs.
matsev authored Oct 23, 2012
445
6705ab5 @jamesward doc updates
authored May 2, 2012
446 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
447
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
448 ```sh
449 git commit -am "add new UI to create Tasks"
450 git diff upstream/java-task_add
451 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
452
453
454 Get Tasks as JSON
455 -----------------
456
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
457 Create a new `getTasks` controller method in the `app/controllers/Application.java` file:
458
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
459 ```java
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
460 public static Result getTasks() {
461 java.util.List<models.Task> tasks = new play.db.ebean.Model.Finder(String.class, models.Task.class).all();
462 return ok(play.libs.Json.toJson(tasks));
463 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
464 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
465
466 Add a new route to the `conf/routes` file to get the tasks as JSON serialized data:
467
468 GET /tasks controllers.Application.getTasks()
469
470
1c3f1f3 @jamesward fixes
authored May 7, 2012
471 After adding a new `Task` load the following URL in your browser:
3b6c289 @jamesward cleanup
authored May 7, 2012
472 [http://localhost:9000/tasks](http://localhost:9000/tasks)
6705ab5 @jamesward doc updates
authored May 2, 2012
473
474
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
475 Verify that you see a Task (or Tasks) in JSON form. If the `contents` property in the JSON is null, then stop the `activator ~run` process, run `activator clean` and then run the app again: `activator ~run`
6705ab5 @jamesward doc updates
authored May 2, 2012
476
477
478 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
479
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
480 ```sh
481 git commit -am "get the tasks as JSON"
482 git diff upstream/java-task_json
483 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
484
485
486 Display the Tasks via CoffeeScript and jQuery
487 ---------------------------------------------
488
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
489 Add the jQuery WebJar to your project by adding the following to your `build.sbt` file:
6705ab5 @jamesward doc updates
authored May 2, 2012
490
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
491
492 libraryDependencies += "org.webjars" % "jquery" % "1.11.2"
493
494 Note: Make sure you have an empty line before the line above.
2a865c8 @jamesward merge changes from other branch
authored May 2, 2012
495
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
496 Restart the `activator ~run` process to reload the dependencies.
497
498 In the body of the `app/views/index.scala.html` file add a place to display the tasks above the form:
499
500 <ul id="tasks"></ul>
2a865c8 @jamesward merge changes from other branch
authored May 3, 2012
501
502 Create a new file named `app/assets/javascripts/index.coffee` (and create the necessary directories) containing a simple CoffeeScript application that uses jQuery to load and display the tasks:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
503
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
504 ```coffee
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
505 $ ->
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
506 $.get "/tasks", (data) ->
507 $.each data, (index, task) ->
508 $("#tasks").append $("<li>").text task.contents
509 ```
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
510
2a865c8 @jamesward merge changes from other branch
authored May 3, 2012
511 This makes a `get` request to `/tasks` for the JSON serialized list of `Task` objects and then adds a new list item to the page element with the id of `tasks` for each `Task`.
512
513
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
514 Update the `app/views/main.scala.html` file to load jQuery from the WebJar and include the compiled version of the `index.coffee` JavaScript:
515
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
516 ```html
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
517 <script src="@routes.Assets.at("lib/jquery/jquery.min.js")" type="text/javascript"></script>
518 <script src="@routes.Assets.at("javascripts/index.js")" type="text/javascript"></script>
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
519 ```
2a865c8 @jamesward merge changes from other branch
authored May 3, 2012
520
b8c3f68 @jamesward updates
authored May 7, 2012
521 Check out the app in your browser and verify that the list of tasks is displayed:
3b6c289 @jamesward cleanup
authored May 7, 2012
522 [http://localhost:9000/](http://localhost:9000/)
6705ab5 @jamesward doc updates
authored May 2, 2012
523
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
524 To see the compiled version of the compiled javascript you can go to [http://localhost:9000/assets/javascripts/index.js](http://localhost:9000/assets/javascripts/index.js)
21d99d5 @matsev Added links to the reference docs.
matsev authored Oct 23, 2012
525
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
526 _Read more about [Assets](https://www.playframework.com/documentation/2.3.x/Assets) and [CoffeeScript](https://www.playframework.com/documentation/2.3.x/AssetsCoffeeScript)_
6705ab5 @jamesward doc updates
authored May 2, 2012
527
528 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
529
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
530 ```sh
531 git add app/views/index.scala.html app/assets/javascripts/index.coffee app/views/main.scala.html
532 git commit -am "Display the list of tasks using jQuery and CoffeeScript"
533 git diff upstream/java-task_coffeescript
534 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
535
536
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
537 Make the App Pretty with Twitter Bootstrap
6705ab5 @jamesward doc updates
authored May 2, 2012
538 ------------------------------------------
539
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
540 [Bootstrap](http://getbootstrap.com) is a CSS library that makes it easy to make a web app look better. To use Bootstrap start by adding the dependency to the `build.sbt` file:
541
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
542 ```scala
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
543
544 libraryDependencies += "org.webjars" % "bootstrap" % "2.1.1"
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
545 ```
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
546
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
547 Note: Make sure you have an empty line before the line above.
548
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
549 Now restart the Play server so that it will fetch the new dependency. To use Bootstrap simply include the following line in the `app/views/main.scala.html` file, making sure it is between the `<title>` and the `main.css` lines:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
550
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
551 ```html
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
552 <link rel="stylesheet" media="screen" href="@routes.Assets.at("lib/bootstrap/css/bootstrap.min.css")">
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
553 ```
02877e3 @peterbarber Added missing line required in routes for webjars
peterbarber authored Feb 28, 2013
554
fe93d75 @jamesward updated tutorial
authored May 7, 2012
555 Add the following to the `public/stylesheets/main.css` file in order to move the main content down to a viewable location:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
556
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
557 ```css
558 body {
559 padding-top: 50px;
560 }
561 ```
fe93d75 @jamesward updated tutorial
authored May 7, 2012
562
563 Create a new template component that will be used to create new Bootstrap-friendly form fields by creating a new file named `app/views/twitterBootstrapInput.scala.html` containing:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
564
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
565 ```html
566 @(elements: helper.FieldElements)
2cdcdbc @jamesward fix indentation
authored May 7, 2012
567
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
568 <div class="control-group @if(elements.hasErrors) {error}">
569 <label for="@elements.id" class="control-label">@elements.label</label>
570 <div class="controls">
571 @elements.input
572 <span class="help-inline">@elements.errors.mkString(", ")</span>
fe93d75 @jamesward updated tutorial
authored May 7, 2012
573 </div>
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
574 </div>
575 ```
fe93d75 @jamesward updated tutorial
authored May 7, 2012
576
577 Update the `app/views/index.scala.html` file to use Bootstrap for a nice header, better layout, and nicer default fonts:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
578
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
579 ```html
580 @(message: String, taskForm: Form[Task])
581 @implicitFieldConstructor = @{ helper.FieldConstructor(twitterBootstrapInput.render) }
2cdcdbc @jamesward fix indentation
authored May 7, 2012
582
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
583 @main("Welcome to Play 2.0") {
2cdcdbc @jamesward fix indentation
authored May 7, 2012
584
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
585 <div class="navbar navbar-fixed-top">
586 <div class="navbar-inner">
587 <div class="container-fluid">
588 <a id="titleLink" class="brand" href="/">@message.toUpperCase</a>
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
589 </div>
590 </div>
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
591 </div>
fe93d75 @jamesward updated tutorial
authored May 7, 2012
592
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
593 <div class="container">
594 <ul id="tasks"></ul>
fe93d75 @jamesward updated tutorial
authored May 7, 2012
595
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
596 @helper.form(action = routes.Application.addTask(), 'class -> "well form-horizontal") {
597 @helper.inputText(taskForm("contents"), '_label -> "Contents")
598 <div class="controls">
599 <input type="submit" class="btn btn-primary"/>
600 </div>
601 }
602 </div>
2cdcdbc @jamesward fix indentation
authored May 7, 2012
603
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
604 }
605 ```
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
606
fe93d75 @jamesward updated tutorial
authored May 7, 2012
607 The template now takes a second parameter that is a `Form[Task]` and must be passed to the template. This will be used for helping with form validation. Update the `index()` method in the `app/controllers/Application.java` file to pass the new required parameter:
608
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
609 ```java
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
610 public static Result index() {
611 return ok(index.render("hello, world", play.data.Form.form(models.Task.class)));
612 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
613 ```
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
614
615 In the `test/ApplicationTest.java` file, update the `indexTemplate` test method:
616
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
617 ```java
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
618 Content html = views.html.index.render("HELLO, WORLD", play.data.Form.form(models.Task.class));
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
619 ```
fe93d75 @jamesward updated tutorial
authored May 7, 2012
620
621 Run the tests to make sure they still pass:
622
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
623 activator test
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
624
625
1c3f1f3 @jamesward fixes
authored May 7, 2012
626 Load the app in your browser and verify it still works:
3b6c289 @jamesward cleanup
authored May 7, 2012
627 [http://localhost:9000/](http://localhost:9000/)
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
628
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
629 _Read more about [Templates](https://www.playframework.com/documentation/2.3.x/JavaTemplates)_
6705ab5 @jamesward doc updates
authored May 2, 2012
630
631 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
632
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
633 ```bash
634 git add app/views/twitterBootstrapInput.scala.html
635 git commit -am "Add Bootstrap"
636 git diff upstream/java-bootstrap
637 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
638
639
640 Add Form Validation
641 -------------------
642
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
643 Add a simple `Required` constraint to `contents` property on the `app/models/Task.java` class:
644
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
645 ```java
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
646 @play.data.validation.Constraints.Required
647 public String contents;
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
648 ```
fe93d75 @jamesward updated tutorial
authored May 7, 2012
649
650 Update the `addTask` method on the `app/controllers/Application.java` controller to check for form errors and if it sees any then render the form instead of trying to save the Task:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
651
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
652 ```java
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
653 public static Result addTask() {
654 play.data.Form<models.Task> form = play.data.Form.form(models.Task.class).bindFromRequest();
655 if (form.hasErrors()) {
656 return badRequest(index.render("hello, world", form));
657 }
658 else {
659 models.Task task = form.get();
660 task.save();
661 return redirect(routes.Application.index());
662 }
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
663 }
664 ```
fe93d75 @jamesward updated tutorial
authored May 7, 2012
665
1c3f1f3 @jamesward fixes
authored May 7, 2012
666 Load the app in your browser verify that adding an empty Task displays an error:
3b6c289 @jamesward cleanup
authored May 7, 2012
667 [http://localhost:9000/](http://localhost:9000/)
6705ab5 @jamesward doc updates
authored May 2, 2012
668
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
669 _Read more about [Validation](https://www.playframework.com/documentation/2.3.x/JavaForms)_
bc007c8 @jamesward add bootstrap instructions
authored May 4, 2012
670
6705ab5 @jamesward doc updates
authored May 2, 2012
671 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
672
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
673 ```sh
674 git commit -am "Add validation"
675 git diff upstream/java-validation
676 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
677
678
679 Update the App on Heroku
680 ------------------------
681
fe93d75 @jamesward updated tutorial
authored May 7, 2012
682 Heroku provides each application with a small, free PostgreSQL database. To switch the application to use that database only when it's running on Heroku, two small changes need to be made.
683
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
684 First, add the PostgreSQL database driver as a dependency by adding the following to the `build.sbt` file:
685
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
686 ```scala
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
687
688 libraryDependencies += "postgresql" % "postgresql" % "9.1-901-1.jdbc4"
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
689 ```
fe93d75 @jamesward updated tutorial
authored May 7, 2012
690
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
691 Note: Make sure you have an empty line before the line above.
fe93d75 @jamesward updated tutorial
authored May 7, 2012
692
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
693 Create a new file named `Procfile` (make sure to capitalize the "P") in order to override the default database settings when Heroku runs the app:
694
695 web: target/universal/stage/bin/play2torial -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL
fe93d75 @jamesward updated tutorial
authored May 7, 2012
696
6705ab5 @jamesward doc updates
authored May 2, 2012
697
698 Commit and verify your changes:
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
699
b1a1ccb @stokito Code highlight
stokito authored Dec 17, 2013
700 ```sh
701 git commit -am "Updates for PostgreSQL on Heroku"
702 git diff upstream/java-heroku_update
703 ```
6705ab5 @jamesward doc updates
authored May 2, 2012
704
fe93d75 @jamesward updated tutorial
authored May 7, 2012
705 Push your updates to Heroku:
706
707 git push heroku master
708
709
710 View your app on the cloud:
711
712 heroku open
713
cc2117c @jamesward more updates for play 2.3
authored Apr 2, 2015
714 _Read more about [Play on Heroku](https://www.playframework.com/documentation/2.3.x/ProductionHeroku)_
fe93d75 @jamesward updated tutorial
authored May 7, 2012
715
716 Congratulations!
717 ----------------
718
6d15e9a Updated tutorial to work with Play 2.3
Justin Livingston authored Feb 2, 2015
719 You've built a Play 2.3 app and deployed it on the cloud. You've learned how to get started with Play 2.3, Ebean, CoffeeScript, Twitter Bootstrap, jQuery, RESTful JSON services, and Heroku. Have fun as you continue to learn Play 2.3!
Something went wrong with that request. Please try again.