Play 2.4 控制台无法按记录工作
play 2.4 console not working as documented
我最近更新了 2.4.1 (damiya) 版本并且总是能够通过 intellij 和在我的终端 window 中输入 activator console
进入 scala 控制台。然后我将通过输入这行代码来启动一个新的静态应用程序:
new play.core.StaticApplication(new java.io.File("."))
如 play website itself 以及对 SO 上类似旧问题的一些答案中所述。
然而,我无法让它在 play 2.4.1 上运行,返回的错误为:
<console>:8: error: type StaticApplication is not a member of package play.core
new play.core.StaticApplication(new java.io.File("."))
^ `
任何关于如何解决这个问题的建议都将不胜感激,控制台在过去对我非常有用,对于调试目的来说相当重要。
Richard 在此 commit 中解释:
Refactored server start code into prod, dev, test modes
This change makes the lifecycle for starting up applications much
clearer.
- No longer need separate ServerStart implementations for Netty and Akka HTTP because ServerProvider configuration is always loaded from
configuration files. Instead, separate out code according to the mode
that the server runs in, because behavior can vary between modes. Now
we have a ProdServerStart, DevServerStart and a DocServerStart.
- For each mode, move the ApplicationProvider code into same file as the new server startup code. Move code for starting up the application
out of the ApplicationProvider constructors and into the server
start code. ApplicationProviders still implement the 'get' method
for getting the current Application.
- Remove TestApplication and StaticApplication, because they do the same thing. Instead provide helpers for 'static' Applications that
don't need reloading.
您可以按照以下方式做同样的事情:
play.core.server.ProdServerStart.main(Array())
不幸的是,bjfletcher 的回答只是让我走上了正确的道路——运行 ProdServerStart
实际上并没有给我一个 运行 环境(事实上,恰恰相反——
scala> play.core.server.ProdServerStart.main(Array.empty)
Oops, cannot start the server.
Configuration error: Configuration error[application: application.conf: java.io.IOException: resource not found on classpath: application.conf, application.json: java.io.IOException: resource not found on classpath: application.json, application.properties: java.io
.IOException: resource not found on classpath: application.properties]
at play.api.Configuration$.configError(Configuration.scala:178)
at play.api.Configuration$.load(Configuration.scala:103)
at play.api.Configuration$.load(Configuration.scala:133)
at play.api.ApplicationLoader$.createContext(ApplicationLoader.scala:91)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:50)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
at $line21.$read$$iw$$iw$.<init>(<console>:8)
at $line21.$read$$iw$$iw$.<clinit>(<console>)
at $line21.$eval$.$print$lzycompute(<console>:7)
at $line21.$eval$.$print(<console>:6)
at $line21.$eval.$print(<console>)
...
...可能是由于我自己对 JVM 缺乏经验。)。
幸运的是,Launch the Interactive Console 的 2.5.x 版本提供了可运行的代码!
我们之前的更详细版本现在是:
import play.api._
val env = Environment(new java.io.File("."), this.getClass.getClassLoader, Mode.Dev)
val context = ApplicationLoader.createContext(env)
val loader = ApplicationLoader(context)
val app = loader.load(context)
Play.start(app)
import Play.current
这可能可以保存到 :script
或其他东西中。
我最近更新了 2.4.1 (damiya) 版本并且总是能够通过 intellij 和在我的终端 window 中输入 activator console
进入 scala 控制台。然后我将通过输入这行代码来启动一个新的静态应用程序:
new play.core.StaticApplication(new java.io.File("."))
如 play website itself 以及对 SO 上类似旧问题的一些答案中所述。
然而,我无法让它在 play 2.4.1 上运行,返回的错误为:
<console>:8: error: type StaticApplication is not a member of package play.core
new play.core.StaticApplication(new java.io.File("."))
^ `
任何关于如何解决这个问题的建议都将不胜感激,控制台在过去对我非常有用,对于调试目的来说相当重要。
Richard 在此 commit 中解释:
Refactored server start code into prod, dev, test modes
This change makes the lifecycle for starting up applications much clearer.
- No longer need separate ServerStart implementations for Netty and Akka HTTP because ServerProvider configuration is always loaded from
configuration files. Instead, separate out code according to the mode that the server runs in, because behavior can vary between modes. Now we have a ProdServerStart, DevServerStart and a DocServerStart.- For each mode, move the ApplicationProvider code into same file as the new server startup code. Move code for starting up the application out of the ApplicationProvider constructors and into the server
start code. ApplicationProviders still implement the 'get' method
for getting the current Application.- Remove TestApplication and StaticApplication, because they do the same thing. Instead provide helpers for 'static' Applications that
don't need reloading.
您可以按照以下方式做同样的事情:
play.core.server.ProdServerStart.main(Array())
不幸的是,bjfletcher 的回答只是让我走上了正确的道路——运行 ProdServerStart
实际上并没有给我一个 运行 环境(事实上,恰恰相反——
scala> play.core.server.ProdServerStart.main(Array.empty)
Oops, cannot start the server.
Configuration error: Configuration error[application: application.conf: java.io.IOException: resource not found on classpath: application.conf, application.json: java.io.IOException: resource not found on classpath: application.json, application.properties: java.io
.IOException: resource not found on classpath: application.properties]
at play.api.Configuration$.configError(Configuration.scala:178)
at play.api.Configuration$.load(Configuration.scala:103)
at play.api.Configuration$.load(Configuration.scala:133)
at play.api.ApplicationLoader$.createContext(ApplicationLoader.scala:91)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:50)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
at $line21.$read$$iw$$iw$.<init>(<console>:8)
at $line21.$read$$iw$$iw$.<clinit>(<console>)
at $line21.$eval$.$print$lzycompute(<console>:7)
at $line21.$eval$.$print(<console>:6)
at $line21.$eval.$print(<console>)
...
...可能是由于我自己对 JVM 缺乏经验。)。
幸运的是,Launch the Interactive Console 的 2.5.x 版本提供了可运行的代码!
我们之前的更详细版本现在是:
import play.api._
val env = Environment(new java.io.File("."), this.getClass.getClassLoader, Mode.Dev)
val context = ApplicationLoader.createContext(env)
val loader = ApplicationLoader(context)
val app = loader.load(context)
Play.start(app)
import Play.current
这可能可以保存到 :script
或其他东西中。