2017-02-13 31 views
0

activator new如何在Play中組織java和scala代碼?

結果:

Fetching the latest list of templates... 



Browse the list of templates: http://lightbend.com/activator/templates 
Choose from these featured templates or enter a template name: 
    1) minimal-akka-java-seed 
    2) minimal-akka-scala-seed 
    3) minimal-java 
    4) minimal-scala 
    5) play-java 
    6) play-scala 
(hit tab to see a list of all templates) 
> 

play-javaplay-scala剖析如下所示:

ls project-*/app 
...-java/app: 
controllers filters Filters.java Module.java services views 

...-scala/app: 
controllers filters Filters.scala Module.scala services views 

根據this文檔:

也可以選擇使用SBT和默認使用的默認佈局。請注意,此佈局是實驗性的,可能有 問題。爲了使用此佈局,您必須禁用佈局 插件,併成立了捻轉模板明確監測:

build.sbt     → Application build script 
src      → Application sources 
└ main     → Compiled asset sources 
    └ java     → Java sources 
     └ controllers  → Java controllers 
     └ models   → Java business layer 
    └ scala    → Scala sources 
     └ controllers  → Scala controllers 
     └ models   → Scala business layer 
    └ resources   → Configurations files and other non-compiled resources (on classpath) 
     └ application.conf → Main configuration file 
     └ routes   → Routes definition 

討論

基於this answer一個應該結合了Java和Scala文件?例如: -

合併

...-java/app/controllers: 
AsyncController.java CountController.java HomeController.java 

...-scala/app/controllers: 
AsyncController.scala CountController.scala HomeController.scala 

.../app/controllers 
AsyncController.java CountController.java HomeController.java 
AsyncController.scala CountController.scala HomeController.scala 

這是Java和Scala類還是應該在Java和Scala目錄中創建相結合的應用程序/ Controllers文件夾播放解剖?

routes文件駐留在Scala和Java項目是相同的:

# Routes 
# This file defines all application routes (Higher priority routes first) 
# ~~~~ 

# An example controller showing a sample home page 
GET /       controllers.HomeController.index 
# An example controller showing how to use dependency injection 
GET  /count      controllers.CountController.count 
# An example controller showing how to write asynchronous code 
GET  /message     controllers.AsyncController.message 

# Map static resources from the /public folder to the /assets URL path 
GET  /assets/*file    controllers.Assets.versioned(path="/public", file: Asset) 

回答

2

只要把你的controllersmodels文件夾到一個文件夾app,並把Scala和java文件裏面。

build.sbt   → Application build script 
app     → Application sources 
└ controllers  → controllers (java or scala) 
└ models   → business layer (java or scala) 
└ views    
public 
conf 
└ application.conf → Main configuration file 
└ routes   → Routes definition 
1

你不需要特殊的「結合」佈局 - 您可以使用Java和Scala在同一個軟件包。

例子:

package controllers; 

public class MyJavaClass { 

    public static String getName(){ 
    return "My Name"; 
    } 
} 

enter image description here