配置 Play Framework 以使用 http 服务器运行

Posted

技术标签:

【中文标题】配置 Play Framework 以使用 http 服务器运行【英文标题】:Configure Play Framework to run with http server 【发布时间】:2014-04-02 03:35:55 【问题描述】:

我使用播放框架 2.2.1

在开发模式下,当我尝试播放运行/启动时,它会使用 Jetty 启动播放应用程序。但是,当我将它打包并部署到另一台机器上并键入相同的命令时,它不会启动任何 http 服务器,而是直接使用 Play 服务器。我该如何配置它,以便它从与开发中相同的 http 服务器开始?

【问题讨论】:

Play 在开发和生产中都使用了 Netty。你是如何在 prod 中启动服务器的? 我在 prod 中启动服务器,同时使用 play start 80 和 play run 80 你如何打包它? 我是用sh脚本打包的。 你不是用play dist打包的吗?您是否阅读过部署文档? playframework.com/documentation/2.2.x/ProductionDist 【参考方案1】:

Play 在开发和生产模式中都使用 Netty。

play run 命令用于在开发模式下执行应用程序。

对于生产,使用play dist 命令创建一个发行版。然后将生成的zip文件复制到生产主机,解压,从包的bin目录运行启动脚本。

见:

Creating a standalone version of your application Additional configuration

此会话日志显示过程:

fernando@fernando-i7-mint ~/work/servicero/servicero-devops $ cd /tmp
fernando@fernando-i7-mint /tmp $ mkdir 0958
fernando@fernando-i7-mint /tmp $ cd 0958
fernando@fernando-i7-mint /tmp/0958 $ play new app1
       _
 _ __ | | __ _ _  _
| '_ \| |/ _' | || |
|  __/|_|\____|\__ /
|_|            |__/

play 2.2.2 built with Scala 2.10.3 (running Java 1.7.0_51), http://www.playframework.com

The new application will be created in /tmp/0958/app1

What is the application name? [app1]
> 

Which template do you want to use for this new application? 

  1             - Create a simple Scala application
  2             - Create a simple Java application

> 1
OK, application app1 is created.

Have fun!

fernando@fernando-i7-mint /tmp/0958 $ cd app1
fernando@fernando-i7-mint /tmp/0958/app1 $ play dist
[info] Loading project definition from /tmp/0958/app1/project
[info] Set current project to app1 (in build file:/tmp/0958/app1/)
[info] Packaging /tmp/0958/app1/target/scala-2.10/app1_2.10-1.0-SNAPSHOT-sources.jar ...
[info] Updating file:/tmp/0958/app1/app1...
[info] Done packaging.
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Wrote /tmp/0958/app1/target/scala-2.10/app1_2.10-1.0-SNAPSHOT.pom
[info] Main Scala API documentation to /tmp/0958/app1/target/scala-2.10/api...
[info] Compiling 5 Scala sources and 1 Java source to /tmp/0958/app1/target/scala-2.10/classes...
model contains 17 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /tmp/0958/app1/target/scala-2.10/app1_2.10-1.0-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] Packaging /tmp/0958/app1/target/scala-2.10/app1_2.10-1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] 
[info] Your package is ready in /tmp/0958/app1/target/universal/app1-1.0-SNAPSHOT.zip
[info] 
[success] Total time: 15 s, completed Apr 2, 2014 9:59:14 AM
fernando@fernando-i7-mint /tmp/0958/app1 $ ls -la target/universal/*.zip
-rw-r--r-- 1 fernando fernando 31442929 Abr  2 09:59 target/universal/app1-1.0-SNAPSHOT.zip
fernando@fernando-i7-mint /tmp/0958/app1 $ cd /tmp
fernando@fernando-i7-mint /tmp $ unzip 0958/app1/target/universal/app1-1.0-SNAPSHOT.zip 
Archive:  0958/app1/target/universal/app1-1.0-SNAPSHOT.zip
  inflating: app1-1.0-SNAPSHOT/lib/default.app1-1.0-SNAPSHOT.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.scala-lang.scala-library-2.10.3.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-jdbc_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.sbt-link-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.javassist.javassist-3.18.0-GA.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-exceptions-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.templates_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.github.scala-incubator.io.scala-io-file_2.10-0.4.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.github.scala-incubator.io.scala-io-core_2.10-0.4.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.jsuereth.scala-arm_2.10-1.3.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-iteratees_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.scala-stm.scala-stm_2.10-0.7.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.config-1.0.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-json_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-functional_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-datacommons_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/joda-time.joda-time-2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.joda.joda-convert-1.3.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.fasterxml.jackson.core.jackson-annotations-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.fasterxml.jackson.core.jackson-core-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.fasterxml.jackson.core.jackson-databind-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.scala-lang.scala-reflect-2.10.3.jar  
  inflating: app1-1.0-SNAPSHOT/lib/io.netty.netty-3.7.0.Final.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.netty.netty-http-pipelining-1.1.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.slf4j.slf4j-api-1.7.5.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.slf4j.jul-to-slf4j-1.7.5.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.slf4j.jcl-over-slf4j-1.7.5.jar  
  inflating: app1-1.0-SNAPSHOT/lib/ch.qos.logback.logback-core-1.0.13.jar  
  inflating: app1-1.0-SNAPSHOT/lib/ch.qos.logback.logback-classic-1.0.13.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-actor_2.10-2.2.0.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.akka.akka-slf4j_2.10-2.2.0.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.apache.commons.commons-lang3-3.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.ning.async-http-client-1.7.18.jar  
  inflating: app1-1.0-SNAPSHOT/lib/oauth.signpost.signpost-core-1.2.1.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/commons-codec.commons-codec-1.3.jar  
  inflating: app1-1.0-SNAPSHOT/lib/oauth.signpost.signpost-commonshttp4-1.2.1.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.apache.httpcomponents.httpcore-4.0.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/org.apache.httpcomponents.httpclient-4.0.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/commons-logging.commons-logging-1.1.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/xerces.xercesImpl-2.11.0.jar  
  inflating: app1-1.0-SNAPSHOT/lib/xml-apis.xml-apis-1.4.01.jar  
  inflating: app1-1.0-SNAPSHOT/lib/javax.transaction.jta-1.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.jolbox.bonecp-0.8.0.RELEASE.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.google.guava.guava-14.0.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.h2database.h2-1.3.172.jar  
  inflating: app1-1.0-SNAPSHOT/lib/tyrex.tyrex-1.0.1.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.anorm_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/com.typesafe.play.play-cache_2.10-2.2.2.jar  
  inflating: app1-1.0-SNAPSHOT/lib/net.sf.ehcache.ehcache-core-2.6.6.jar  
  inflating: app1-1.0-SNAPSHOT/bin/app1  
  inflating: app1-1.0-SNAPSHOT/bin/app1.bat  
  inflating: app1-1.0-SNAPSHOT/conf/application.conf  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/package.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/Routes$.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/views/package.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/views/html/main$.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/views/html/index$.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/views/html/package.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/jquery.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/signaturebg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/class_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/package_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/tools.tooltip.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/template.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filter_box_right.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/package.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/unselected.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/trait_to_object_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/index.css  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filterboxbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/constructorsbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filterboxbarbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/object_diagram.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/diagrams.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/index.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/selected-right.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/jquery-ui.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/trait_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/ownerbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/trait.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/selected2.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/signaturebg2.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/ref-index.css  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filterboxbarbg.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/selected2-right.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/object.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/object_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/type_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/arrow-right.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/selected.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/type.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/object_to_type_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/class.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/type_diagram.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/type_to_object_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/remove.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/object_to_class_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/fullcommenttopbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/selected-right-implicits.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/defbg-green.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/trait_diagram.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filter_box_left2.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/conversionbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/modernizr.custom.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/object_to_trait_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filterbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/filter_box_left.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/ownderbg2.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/ownerbg2.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/navigation-li-a.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/class_to_object_big.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/jquery.layout.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/diagrams.css  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/navigation-li.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/defbg-blue.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/template.css  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/valuemembersbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/arrow-down.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/scheduler.js  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/selected-implicits.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/packagesbg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/typebg.gif  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/lib/class_diagram.png  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/ReverseAssets.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/routes.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/Application$.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/package.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/ReverseApplication.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/ref/ReverseAssets.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/ref/package.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/ref/ReverseApplication.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/javascript/ReverseAssets.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/javascript/package.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/controllers/javascript/ReverseApplication.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-v.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-s.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-c.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-a.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-r.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-f.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-h.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-i.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-d.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-m.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-j.html  
  inflating: app1-1.0-SNAPSHOT/share/doc/api/index/index-p.html  
  inflating: app1-1.0-SNAPSHOT/README  
fernando@fernando-i7-mint /tmp $ cd app1-1.0-SNAPSHOT/
fernando@fernando-i7-mint /tmp/app1-1.0-SNAPSHOT $ ls -la
total 28
drwxr-xr-x  6 fernando fernando 4096 Abr  2 10:00 .
drwxrwxrwt 14 root     root     4096 Abr  2 10:00 ..
drwxr-xr-x  2 fernando fernando 4096 Abr  2 10:00 bin
drwxr-xr-x  2 fernando fernando 4096 Abr  2 10:00 conf
drwxr-xr-x  2 fernando fernando 4096 Abr  2 10:00 lib
-rw-r--r--  1 fernando fernando  147 Fev 28 14:45 README
drwxr-xr-x  3 fernando fernando 4096 Abr  2 10:00 share
fernando@fernando-i7-mint /tmp/app1-1.0-SNAPSHOT $ ls -la bin
total 28
drwxr-xr-x 2 fernando fernando  4096 Abr  2 10:00 .
drwxr-xr-x 6 fernando fernando  4096 Abr  2 10:00 ..
-rwxr-xr-x 1 fernando fernando 11510 Abr  2 09:59 app1
-rw-r--r-- 1 fernando fernando  5732 Abr  2 09:59 app1.bat
fernando@fernando-i7-mint /tmp/app1-1.0-SNAPSHOT $ bin/app1
Play server process ID is 4582
[info] play - Application started (Prod)
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

【讨论】:

它似乎使用 play run 来启动播放服务器。如何编辑 app1 脚本,使其使用 play start 或 play stage 来启动 http 服务器? @Mullex play dist生成的app1脚本不使用play run。它启动预编译和打包的应用程序。该脚本旨在在生产环境中按原样执行。你想达到什么目的? 我想在后台运行播放。但是使用 app1 脚本,它似乎只能在前台开始播放。 对,这是一个不同的问题。基本上,您需要一个初始化脚本/守护程序/服务,具体取决于您正在运行的操作系统和发行版。参见例如gist.github.com/THemming/2173037、gist.github.com/bihe/1240920。

以上是关于配置 Play Framework 以使用 http 服务器运行的主要内容,如果未能解决你的问题,请参考以下文章

Play Framework:如何不查看文件夹以了解 Play Framework 中的更改

Play Framework 作为 SBT 非根模块

Play Framework (2.5) - JMX port enable to see in JVisualVM

无法使用 Play Framework 向浏览器提供文件以供下载

HikariCP - Play Framework 1.2.7 JMX MBean 监控

Play Framework2.5 repositories文件配置