java - 如何在 Play 中组织 java 和 scala 代码?

标签 java scala playframework typesafe-activator

激活器新

结果:

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文档:

You also have the option of using the default layout used by SBT and Maven. Please note that this layout is experimental and may have issues. In order to use this layout, you must disable the layout plugin and set up explicit monitoring for twirl templates:

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 类的 Play 剖析,还是应该在 app/controllers 文件夹中创建 java 和 scala 目录?

驻留在 scala 和 java 项目中的 routes 文件是相同的:

# 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)

最佳答案

只需将您的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

关于java - 如何在 Play 中组织 java 和 scala 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42205131/

相关文章:

scala - Scala 中的 for 表达式与 foreach

performance - Haskell Vector 性能与 Scala 相比

intellij-idea - 如何在 IntelliJ IDEA 中以 Debug模式运行 Play Framework 2.x?

java - Play 2 JPA Oracle - 即使 ebeanEnabled 在 build.scala 中设置为 false,也会出现额外列 'ebean_intercept'

java - 如何在运行程序文件中给出功能文件的路径

java - JPQL/HQL : select with OR fails

java - 将字符串转换为字符时出现 StringIndexOutOfBoundsException。可能的原因?

java - 如何连续扫描输入到控制台?

检查匹配括号的算法

scala - mongodb数据库与scala play 2.0教程