2013-05-25 45 views
3

我目前正在進行Play! 2.1.1應用程序定義多個子項目。這裏是我的Build.scala:使用Play框架訪問子項目中的資產2.1.1

val lfamName = "lfam" 
val lfamVersion = "1.0-SNAPSHOT" 
val lfamDirectory = "subprojects/" + lfamName 
lazy val lfam = play.Project(lfamName, lfamVersion, appDependencies, path = file(lfamDirectory)) 

val mainName = "main" 
val mainVersion = "1.0-SNAPSHOT" 
lazy val main = play.Project(mainName, mainVersion, appDependencies) 
      .settings().dependsOn(lfam).aggregate(lfam) 

產生的struture:

app 
    └ controllers 
    └> Application.scala 
    └ models 
    └ views 
    └> index.scala.html 
    └ assets 
    └ stylesheets 
     └> main.less 
conf 
    └> application.conf 
    └> routes 
subprojects 
    └ lfam 
    └ conf 
     └> lfam.routes 
    └ app/controllers 
     └> Application.scala 
     └> Assets.scala 
    └ app/models 
    └ app/views 
     └> index.scala.html 
    └ assets 
     └ stylesheets 
     └> main.less 

來源:

路線

​​

lfam.routes

GET /       controllers.lfam.Application.index 

GET  /assets/*file    controllers.lfam.Assets.at(path="/public", file) 

Assets.scala

package controllers.lfam 
object Assets extends controllers.AssetsBuilder 

Application.scala(只是項目之間的包名稱更改)

package controllers(.lfam) 

import play.api._ 
import play.api.mvc._ 

object Application extends Controller { 

    def index = Action { 
    Ok(views.html.index()) 
    } 

} 

main.less(主體工程)

@main-color: #0000ff; 

h1 { 
    color: @main-color; 
} 

main.less( lfam項目)

@main-color: #ff0000; 

h1 { 
    color: @main-color; 
} 

index.scala.html(主項目)

<!DOCTYPE HTML> 
<html> 
    <head> 
     <link rel="stylesheet" href="@routes.Assets.at("stylesheets/main.css")"> 
    </head> 
    <body> 
     <h1>Header</h1> 
    </body> 
</html> 

index.scala.html(lfam項目)

<!DOCTYPE HTML> 
<html> 
    <head> 
     <link rel="stylesheet" href="@lfam.routes.Assets.at("stylesheets/main.css")"> 
    </head> 
    <body> 
     <h1>Header</h1> 
    </body> 
</html> 

當顯示子項目指數(/ lfam /)標題是仍然藍色。但是,如果我將main.less文件從子項目重命名爲lfam.less(和html中的對應項),則標題將變爲紅色(如預期的那樣)。

是否有可能在多個子項目中擁有多個資產,並且名稱相同?在第一種情況下,play不是爲我提供正確的css文件,而是找到第二個文件?

感謝

回答