简体   繁体   English

播放框架无法运行现有项目

[英]play framework unable to run an existing project

I'm a rookie developer trying to run an application using play framework. 我是一个新手开发者,试图使用play框架运行应用程序。 I've followed the tutorial and can successfully create a new project. 我已经按照教程学习并成功创建了一个新项目。

However when I go to the directory that has the project I'm supposed to work on and enter the play command I get the following error: 但是,当我进入具有我应该工作的项目的目录并输入播放命令时,我收到以下错误:

[error] Not a valid command: play (similar: last, alias, loadp)
[error] Not a valid project ID: play
[error] Not a valid configuration: play
[error] Not a valid key: play (similar: clean)
[error] play

I have very little knowledge regarding the framework and don't know where to start correcting my mistake. 我对该框架知之甚少,不知道从哪里开始纠正我的错误。 Any suggestions ? 有什么建议 ?

You have to run the play command this way: 你必须以这种方式运行play命令:

./play cmd [app_path] [--options]

where in case of running a project, it is 在运行项目的情况下,它是

./play run /path/to/projectname

I am facing this problem in the context of sub projects. 我在子项目的背景下面临这个问题。

This is what worked for me. 这对我有用。


Code: 码:

import sbt._
import sbt.Keys._

object ApplicationBuild extends Build {

  val helloWorldProj = Project(id = "HelloWorld", base = file("helloworld"))    

  val appName = "WebApp"
  val appVersion = "1.0"
  val appDependencies = Seq()

  val webAppProj = PlayProject( appName, appVersion, appDependencies, path = file("webapp"), mainLang = PlayProject.SCALA)
    .dependsOn(helloWorldProj)
    .aggregate(helloWorldProj)

}

On running the play command, I get the following error: 在运行play命令时,我收到以下错误:

Error: 错误:

[info] Set current project to HelloWorld (in build file:/D:/EclipseProjects/HelloWorldPlayMultiProject/)
[error] Not a valid command: play (similar: last, alias, loadp)
[error] Not a valid project ID: play
[error] Not a valid configuration: play
[error] Not a valid key: play (similar: play-hash, play-dist, play-conf)
[error] play
[error]     ^

Solution: 解:

Now, if I rename helloWorldProj as zhelloWorldProj , it works! 现在,如果我将helloWorldProj重命名为zhelloWorldProj ,它就可以了! In this case, play sets the active project to WebApp .(Since webAppProj variable name alphabetically comes before zhelloWorldProj ) 在这种情况下, play将活动项目设置为WebApp 。(因为webAppProj变量名按字母顺序排在zhelloWorldProj之前)

I can then change the active project to HelloWorld by giving the command project HelloWorld . 然后我就可以改变活动项目HelloWorld通过为命令project HelloWorld

I think this has something to do with how sbt finds the Project objects using reflection. 我认为这与sbt如何使用反射查找Project对象有关。

I delete all directories in the project folder and it works. 我删除项目文件夹中的所有目录,它的工作原理。 Do not delete files (build.properties, Build.scala and plugins.sbt) 不要删除文件(build.properties,Build.scala和plugins.sbt)

需要有关于你的环境(操作系统,播放版本等)的更多细节,但是如果你得到的错误是游戏不是一个有效的命令,我的第一个行动方案是检查play.sh的路径(我假设你是使用非Windows)包含在您的系统路径中?

The problem was the version difference of play. 问题是游戏的版本差异。 The project I was suppose to work on was developed in play 1.2 where as I installed the version 2.0 . 我想要开发的项目是在play 1.2中开发的,我安装了2.0版本。

By the way, working with 2.0 on a project developed by version 1.2 is possible, but I strongly recommend not to do it that way as there are problems on the later stages as well. 顺便说一句,在版本1.2开发的项目上使用2.0是可能的,但我强烈建议不要这样做,因为后期阶段也存在问题。

Depending on the language you're using, make sure one of the following is in your build.sbt file: 根据您使用的语言,确保您的build.sbt文件中包含以下内容之一:
play.Project.playJavaSettings play.Project.playJavaSettings
play.Project.playScalaSettings play.Project.playScalaSettings

I also got the same problem! 我也遇到了同样的问题! What happened was in my /user/xxx/project folder there were old projects from 1.x version. 发生了什么事在我的/ user / xxx / project文件夹中有1.x版本的旧项目。 Deleting that folder worked for me! 删除该文件夹对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM