背景:

一个老板找到我,他有一个项目是用play 框架写的,我从来没有听说java还有一个play 框架。回来以后我去网上查了一下,play框架是一个轻量级的全栈开发框架,完全背离了传统servlet的风格。

play 框架在国内使用并不多,使用简单易上手,开发大型项目也能胜任,这样的项目原来设计者设计完以后,一旦离开原来的工作岗位,后期开发迭代只能交给新人,增加了开发维护成本。

运行环境:

jdk 17,官方网站 下载sbt 1.9.8 二进制包,并解压到某个目录下,配置环境变量%SBT_HOMR%\bin,命令行输入 sbt sbtVersion 查看是否有信息显示。

下载:

我在play 官方网站下载了hello_word_tutoral,看了readme

复制代码
# Play Hello World Web Tutorial for Java

To follow the steps in this tutorial, you will need the correct version of Java and sbt. The tutorial requires:

* Java Software Developer's Kit (SE) 11 or higher
* sbt 1.9.6 or higher.

To check your Java version, enter the following in a command window:

```bash
java -version
```

To check your sbt version, enter the following in a command window:

```bash
sbt sbtVersion
```

If you do not have the required versions, follow these links to obtain them:

* [Java SE](https://adoptium.net/)
* [sbt](http://www.scala-sbt.org/download.html)

## Build and run the project

This example Play project was created from a seed template. It includes all Play components and an Pekko HTTP server. The project is also configured with filters for Cross-Site Request Forgery (CSRF) protection and security headers.

To build and run the project:

1. Use a command window to change into the example project directory, for example: `cd play-java-hello-world-tutorial`

2. Build the project. Enter: `sbt run`. The project builds and starts the embedded HTTP server. Since this downloads libraries and dependencies, the amount of time required depends partly on your connection's speed.

3. After the message `Server started, ...` displays, enter the following URL in a browser: <http://localhost:9000>

The Play application responds: `Welcome to the Hello World Tutorial!`

## Server backend

By default, the project uses the Pekko HTTP Server backend. To switch to the Netty Server backend, enable the `PlayNettyServer` sbt plugin in the `build.sbt` file.
In the `build.sbt` of this project, you'll find a commented line for this setting; simply uncomment it to make the switch.
For more detailed information, refer to the Play Framework [documentation](https://www.playframework.com/documentation/3.0.x/Server).
复制代码

按照readme 的步骤运行起来demo

运行:

cd 进入项目根目录,命令行输入sbt run 即可下载依赖并启动程序

 即可在浏览器地址栏输入 <http://localhost:9000>,回车可查看到页面正常加载出来信息了。

后记:

即使你导入项目到idea 且通过上述步骤下载了依赖,你在idea 开发工具中依然会看到play 包爆红,这个问题怎么解决,这个是我下一篇博客将会谈到的情况。