02.快速入門‎ > ‎

使用Play2.0終端機

Using the Play 2.0 console, https://github.com/playframework/Play20/wiki/PlayConsole


Launching the console

The Play 2.0 console is a development console based on sbt that allows you to manage a Play application’s complete development cycle.

To launch the console, enter any existing Play application directory and run the play script:

$ cd /path/to/any/application
$ play 

Getting help

Use the help play command to get basic help about the available commands:

[My first application] $ help play

Running the server in development mode

To run the current application in development mode, use the run command:

[My first application] $ run

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.

If there are any compilation errors you will see the result of the compilation directly in your browser:

To stop the server, type Crtl+D key, and you will be returned to the Play console prompt.

Compiling

In Play 2.0 you can also compile your application without running the server. Just use the compilecommand:

[My first application] $ compile

Launch the interactive console

Type console to enter the interactive Scala console, which allows you to test your code interactively:

[My first application] $ console

Debugging

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:

$ play debug

When a JPDA port is available, the JVM wil log this line during boot:

Listening for transport dt_socket at address: 9999

Note: Using play debug the JPDA socket will be opened on port 9999. You can also set theJPDA_PORT environment variable yourself using set JPDA_PORT=1234.

使用 sbt 特色 - 觸發執行

The Play console is just a normal sbt console, so you can use sbt features such as triggered execution.

For example, using ~ compile

[My first application] $ ~ compile

The compilation will be triggered each time you change a source file.

If you are using ~ run

[My first application] $ ~ run

The triggered compilation will be enabled while a development server is running.

You can also do the same for ~ test, to continuously test your project each time you modify a source file:

[My first application] $ ~ test

Using the play commands directly

You can also run commands directly without entering the Play console. For example, enterplay run:

$ play run
[info] Loading project definition from myFirstApp/project
[info] Set current project to My first application

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on port 9000...

(Server started, use Ctrl+D to stop and go back to the console...)

The application starts directly. When you quit the server using Ctrl+D, you will come back to your OS prompt.

Force clean

If something goes wrong and you think that the sbt cache is corrupted, use the clean-allcommand for your OS command line to clean all generated directories.

$ play clean-all

Next: Setting-up your preferred IDE



Welcome to Play 2.0!

These commands are available:
-----------------------------
classpath                  Display the project classpath.
clean                      Clean all generated files.
compile                    Compile the current application.
console                    Launch the interactive Scala console (use :quit to exit).
dependencies               Display the dependencies summary.
dist                       Construct standalone application package.
exit                       Exit the console.
h2-browser                 Launch the H2 Web browser.
license                    Display licensing informations.
package                    Package your application as a JAR.
play-version               Display the Play version.
publish                    Publish your application in a remote repository.
publish-local              Publish your application in the local repository.
reload                     Reload the current application build file.
run <port>                 Run the current application in DEV mode.
test                       Run Junit tests and/or Specs from the command line
eclipsify                  generate eclipse project file
start <port>               Start the current application in another JVM in PROD mode.
update                     Update application dependencies.

Type `help` to get the standard sbt help.


[p0204] $ h2-browser
[info] Updating {file:/Volumes/SSD6402/MyBitBucket/play2app/p0204/}p0204...
[info] Done updating.                                                                  
Web Console server running at http://192.168.43.46:8082 (only local connections)
TCP server running at tcp://192.168.43.46:9092 (only local connections)
PG server running at pg://192.168.43.46:5435 (only local connections)
[p0204] $ 


子網頁 (1): Run, Start and Ports
Comments