我能够解决我的问题。我不知道IntelliJ 是如何编译play 项目的,但我注意到如果所需的文件放在公用文件夹中,那么IntelliJ 将部署这些文件。
1) 我在build.sbt创建了一个sbt任务
/* task to Copy files in ../common/css and ../common/javascripts in public/stylesheet/common and public/javascripts/common*/
val copyCommonFilesInPublicKey = taskKey[Int]("Copies files in ../common/css and ../common/javascripts in public/stylesheet/common and public/javascripts/common")
/*
the xcopy command is used to copy all the files and folders [/s] newer than those already copied [/d], including empty folders [/e]. 'common' folder in destination is assumed to be a
directory [/i] and xcopy will not seek permission to overwrite files [/y]
*/
copyCommonFilesInPublicKey := {
val copyCSS = Process(Seq("xcopy", "/i", "/s","/y","/d","/e","..\\common\\css", "public\\stylesheets\\common\\")).!<
println(s"copy CSS returned ${copyCSS}")
val copyJS = Process(Seq("xcopy", "/i","/s", "/y","/d","/e","..\\common\\javascripts", "public\\javascripts\\common\\")).!<
println(s"copy JS returned ${copyJS}")
copyJS
}
2) 我在 IntelliJ 中创建了一个新的 sbt 任务,它将使用在步骤 1 中创建的任务 Run -> Edit Configurations -> + (on top left) -> sbt Task。我把它命名为move files to public,在Tasks中给了copyCommonFilesInPublicKey
3) 我编辑了默认的Play2Run 配置。 Edit Configuration -> select play2Run -> + (on right side this time) -> select Run Another Conguration -> selected moves file to public (created in step 2) -> moved this new configuration above Play2Run built
现在公共文件被移动到公共文件夹,我可以从那里在代码中访问它们,如下所示:
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/common/css-reset.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/common/common-styles.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/common/vendor/bootstrap/bootstrap.css")">