草庐IT

关于 scala:play 2.4 控制台未按记录工作

codeneng 2023-03-28 原文

play 2.4 console not working as documented

我最近更新到播放 2.4.1 (damiya) 版本,并且一直能够通过 intellij 和在我的终端窗口中输入 activator console 进入 scala 控制台。然后我会通过输入这行代码来启动一个新的静态应用程序:

new play.core.StaticApplication(new java.io.File("."))

正如游戏网站本身以及对 SO 上类似旧问题的一些答案所记录的那样。

但是,我无法让它在 play 2.4.1 上运行,错误返回为:

1
2
3
<console>:8: error: type StaticApplication is not a member of package play.core
          new play.core.StaticApplication(new java.io.File("."))
                        ^ `

任何有关如何解决此问题的建议将不胜感激,控制台在过去对我非常有用,并且对于调试目的相当重要。


Richard 在此提交中解释说:

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.

你可以这样做:

1
play.core.server.ProdServerStart.main(Array())

  • 我正在使用来自 github.com/tuplejump/play-yeoman 的 play-yeoman,它添加了对 angular 框架的支持,但找不到与 yeoman 相关的路线。


不幸的是,bjfletcher 的回答只为我指明了正确的道路——运行 ProdServerStart 实际上并没有给我一个运行环境(事实上,恰恰相反——

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 缺乏经验。)。

幸运的是,2.5.x 版本的 Launch the Interactive Console 提供了可运行的代码!

我们之前拥有的更详细的版本现在是:

1
2
3
4
5
6
7
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 或其他东西中。

有关关于 scala:play 2.4 控制台未按记录工作的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  4. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  5. ruby - Sinatra:运行 rspec 测试时记录噪音 - 2

    Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/

  6. ruby-on-rails - 带 Spring 锁的 Rails 4 控制台 - 2

    我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.

  7. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

  8. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

  9. ruby-on-rails - openshift 上的 rails 控制台 - 2

    我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新ruby​​gems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems

  10. ruby-on-rails - Rails 5 Active Record 记录无效错误 - 2

    我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa

随机推荐