1 | # Creating a new application |
---|
2 | |
---|
3 | ## Create a new application with the play command |
---|
4 | |
---|
5 | The easiest way to create a new application is to use the `play new` command. |
---|
6 | |
---|
7 | ```bash |
---|
8 | $ play new myFirstApp |
---|
9 | ``` |
---|
10 | |
---|
11 | This will ask for some information. |
---|
12 | |
---|
13 | - The application name (just for display, this name will be used later in several messages). |
---|
14 | - The template to use for this application. You can choose either a default Scala application, a default Java application, or an empty application. |
---|
15 | |
---|
16 | [[images/playNew.png]] |
---|
17 | |
---|
18 | > Note that choosing a template at this point does not imply that you canât change language later. For example, you can create a new application using the default Java application template and start adding Scala code whenever you like. |
---|
19 | |
---|
20 | Once the application has been created you can use the `play` command again to enter the [[Play 2.0 console | PlayConsole]]. |
---|
21 | |
---|
22 | ```bash |
---|
23 | $ cd myFirstApp |
---|
24 | $ play |
---|
25 | ``` |
---|
26 | |
---|
27 | ## Create a new application without having Play installed |
---|
28 | |
---|
29 | You can also create a new Play application without installing Play, by using sbt. |
---|
30 | |
---|
31 | > First install [[sbt 0.11.2 | https://github.com/harrah/xsbt/wiki/Getting-Started-Setup]] if needed. |
---|
32 | |
---|
33 | Just create a new directory for your new application and configure your sbt build script with two additions. |
---|
34 | |
---|
35 | In `project/plugins.sbt`, add: |
---|
36 | |
---|
37 | ```scala |
---|
38 | // The Typesafe repository |
---|
39 | resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" |
---|
40 | |
---|
41 | // Use the Play sbt plugin for Play projects |
---|
42 | addSbtPlugin("play" % "sbt-plugin" % "2.0") |
---|
43 | ``` |
---|
44 | |
---|
45 | Be sure to replace `2.0` here by the exact version you want to use. If you want to use a snapshot version, you will have to specify this additional resolver: |
---|
46 | |
---|
47 | ``` |
---|
48 | // Typesafe snapshots |
---|
49 | resolvers += "Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/" |
---|
50 | ``` |
---|
51 | |
---|
52 | In `project/Build.scala`: |
---|
53 | |
---|
54 | ```scala |
---|
55 | import sbt._ |
---|
56 | import Keys._ |
---|
57 | import PlayProject._ |
---|
58 | |
---|
59 | object ApplicationBuild extends Build { |
---|
60 | |
---|
61 | val appName = "My first application" |
---|
62 | val appVersion = "1.0" |
---|
63 | |
---|
64 | val appDependencies = Nil |
---|
65 | |
---|
66 | val main = PlayProject( |
---|
67 | appName, appVersion, appDependencies, mainLang = SCALA |
---|
68 | ) |
---|
69 | |
---|
70 | } |
---|
71 | ``` |
---|
72 | |
---|
73 | You can then launch the sbt console in this directory: |
---|
74 | |
---|
75 | ```bash |
---|
76 | $ cd myFirstApp |
---|
77 | $ sbt |
---|
78 | ``` |
---|
79 | |
---|
80 | sbt will load your project and fetch the dependencies. |
---|
81 | |
---|
82 | > **Next:** [[Anatomy of a Play 2.0 application | Anatomy]] |
---|