play framework 2.x 是使用scala与java开发的一款框架、不能说是一个框架应该说是一种解决方案。
play framework 优点有如下几个:
- 开发效率高、scala的特点函数式编程。
- 无状态、可扩展性极好。
- 热部署、修改源码直接动态编译、无需重启服务。
- 优秀的RESTFul框架。
- Play的生态圈在不断扩开。
使用介绍
- jdk1.8环境安装 (忽略)
- SBT安装
- 模板框架使用
SBT安装
使用版本为当前文章时间点的最新版本1.2.8
Homebrew mac系统
brew install sbt@1
所有平台压缩包 sbt-1.2.8.zip
配置sbt的环境、与Java环境配置一样
成功安装如下
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] $
创建Java模板项目
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
运行项目(首次运行项目会下载包、这时间可以去喝一杯咖啡)
cd test
sbt run
成功结尾显示如下
[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...)
创建Scala模板项目(同上)
sbt new playframework/play-scala-seed.g8
cd test
sbt run
其它
访问不存在的接口则显示如下
Intellij-idea debug调试如下
- debug方式运行
sbt run -jvm-debug 9999
- 创建远程连接
- 直接对代码debug即可
最后
后面会继续出play framework实战系列的文章、我在这等你。
网友评论