playframework - Tutorial

Keywords: Java github Scala Programming

play framework 2.x is a framework developed with scala and java. It can't be said to be a framework, but a solution.

The advantages of play framework are as follows:

  1. High efficiency of development and functional programming of scala.
  2. Stateless and scalable.
  3. Hot deployment, direct dynamic compilation of source code modification, no need to restart the service.
  4. Excellent RESTFul framework.
  5. Play's ecosystem is expanding.

Introduction

  1. jdk1.8 environment installation (ignored)
  2. SBT installation
  3. Template framework use

SBT installation

Use the latest version of 1.2.8 at the time of the current article

Homebrew mac system

brew install sbt@1

All platform compression packages sbt-1.2.8.zip

The environment of sbt is the same as that of Java

Successfully installed as follows

sbt -v
[process_args] java_version = '8'
# Executing command line:
java
-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxMetaspaceSize=256m
-jar
/usr/local/Cellar/sbt/1.2.8/libexec/bin/sbt-launch.jar

[info] Loading global plugins from /Users/lake/.sbt/1.0/plugins
[info] Loading settings for project cc-build from plugins.sbt ...
[info] Loading project definition from /Users/lake/dounine/github/zhuxueyuan-play/cc/cc/project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to cc (in build file:/Users/lake/dounine/github/zhuxueyuan-play/cc/cc/)
[info] sbt server started at local:///Users/lake/.sbt/1.0/server/dd2dc1e31d073ed11adb/sock
[cc] $

Create a Java template project

sbt new playframework/play-java-seed.g8
[info] Loading global plugins from /Users/lake/.sbt/1.0/plugins
[info] Set current project to cc (in build file:/Users/lake/dounine/github/cc/)
[info] Set current project to cc (in build file:/Users/lake/dounine/github/cc/)

This template generates a Play Java project 

name [play-java-seed]: test
organization [com.example]: com.dounine    

Template applied in /Users/lake/dounine/github/cc/./test

Run the project (the first run project will download the package, and you can have a cup of coffee at this time)

cd test
sbt run

The successful end is as follows

[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.

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

[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Enter to stop and go back to the console...)

Access page http://localhost:9000

Create Scala template project (same as above)

sbt new playframework/play-scala-seed.g8
cd test
sbt run

Other

Access to non-existent interfaces is shown as follows

IntelliJ idea debug is as follows

  1. Run in debug mode
sbt run -jvm-debug 9999
  1. Create a remote connection

  1. Just debug the code directly

Last

Later, I will continue to publish the play framework practical series, and I will wait for you here.

Posted by cbrian on Sun, 10 Nov 2019 07:15:19 -0800