Scala 的play框架的目录结构

Scala 的play框架的目录结构

play应用布局

play应用的布局是一个保持尽量简单的标准。成功编译之后,play应用目录应该包含如下内容:

app                      → Application sources
 └ assets                → Compiled asset sources
    └ stylesheets        → Typically LESS CSS sources
    └ javascripts        → Typically CoffeeScript sources
 └ controllers           → Application controllers
 └ models                → Application business layer
 └ views                 → Templates
build.sbt                → Application build script
conf                     → Configurations files and other non-compiled resources (on classpath)
 └ application.conf      → Main configuration file
 └ routes                → Routes definition
dist                     → Arbitrary files to be included in your projects distribution
public                   → Public assets
 └ stylesheets           → CSS files
 └ javascripts           → Javascript files
 └ images                → Image files
project                  → sbt configuration files
 └ build.properties      → Marker for sbt project
 └ plugins.sbt           → sbt plugins including the declaration for Play itself
lib                      → Unmanaged libraries dependencies
logs                     → Logs folder
 └ application.log       → Default log file
target                   → Generated stuff
 └ resolution-cache      → Info about dependencies
 └ scala-2.11
    └ api                → Generated API docs
    └ classes            → Compiled class files
    └ routes             → Sources generated from routes
    └ twirl              → Sources generated from templates
 └ universal             → Application packaging
 └ web                   → Compiled web assets
test                     → source folder for unit or functional tests
app/目录

app目录包含所有可执行组件,Java和Scala源代码,模板和编译后的资源。在app目录一共有三个包,分别代表mvc架构模式的组件

  • app/controllers
  • app/models
  • app/views

当然,你也可以添加你自己的包,例如app/utils。

请注意,在Play中,控制器,模型和视图包名称可以根据需要进行更改(例如使用com.yourcompany作为所有内容前缀)。
public/目录

存储在public目录中的资源是由Web服务器直接提供的静态资源。

该目录分为三个子目录,分别用于图像,CSS样式表和JavaScript文件。您应该这样组织静态资源,以保持所有Play应用程序的一致性。

在新创建的应用程序中,/public目录映射到/assets URL路径,但您可以轻松地更改它,甚至可以为静态资产使用多个目录。
conf/目录

conf目录包含应用程序的配置文件。有两个主要配置文件:

  • application.conf, 应用程序的主配置文件,包含配置参数。
  • routes, 路由定义文件。

如果需要添加特定于应用程序的配置选项,最好在application.conf文件中添加更多选项。

如果某些库需要特定的配置文件,建议将其存放在conf目录下。

lib/目录

lib目录是可选的,包含未管理的依赖库。即,您要在构建系统外手动管理的所有JAR文件。只需要将需要的jar文件放入该目录,它们就会被添加到您的应用程序类路径中。

build.sbt/目录

您项目的主要构建声明通常位于项目根目录的build.sbt中。project/目录中的.scala文件也可用于声明项目的构建。

project/目录

项目目录包含sbt构建定义:

  • plugins.sbt 定义此项目使用的sbt插件
  • build.properties 包含用于构建应用程序的sbt版本。
target/目录

target/目录包含构建系统生成的所有内容。知道这里生成的内容会很有用。

  • classes/ 包含所有已编译的类(来自Java和Scala的源代码)。
  • classes_managed/ 仅包含框架管理的类(例如路由器或模板系统生成的类)。在IDE项目中将此类文件夹添加为外部类文件夹会很有用。
  • resource_managed/ 包含生成的资源,通常是编译后的资源,如LESS CSS和CoffeeScript编译结果。
  • src_managed/ 包含生成的代码,例如模板系统生成的Scala源代码
  • web/ 包含由sbt-web处理的资源,例如来自app/assets和public目录的资源。
典型的.gitignore文件

版本控制系统应忽略生成的文件夹。以下是Play应用程序的典型.gitignore文件:

logs
project/project
project/target
target
tmp
dist
.cache
默认SBT布局

您还可以选择使用SBT或Maven的默认布局。请注意,此布局是实验性的,可能存在问题。为使用该默认布局, you must disable the layout plugin and set up explicit monitoring for twirl templates:

disablePlugins(PlayLayoutPlugin)
PlayKeys.playMonitoredFiles ++= (sourceDirectories in (Compile, TwirlKeys.compileTemplates)).value

这将阻止Play覆盖默认的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
    └ twirl
       └ views             → Templates
    └ assets               → Compiled asset sources
       └ css               → Typically LESS CSS sources
       └ js                → Typically CoffeeScript sources
    └ public               → Public assets
       └ css               → CSS files
       └ js                → Javascript files
       └ images            → Image files
 └ test                    → Unit or functional tests
    └ java                 → Java source folder for unit or functional tests
    └ scala                → Scala source folder for unit or functional tests
    └ resources            → Resource folder for unit or functional tests
 └ universal               → Arbitrary files to be included in your projects distribution
project                    → sbt configuration files
 └ build.properties        → Marker for sbt project
 └ plugins.sbt             → sbt plugins including the declaration for Play itself
lib                        → Unmanaged libraries dependencies
logs                       → Logs folder
 └ application.log         → Default log file
target                     → Generated stuff
 └ scala-2.11.12
    └ cache
    └ classes              → Compiled class files
    └ classes_managed      → Managed class files (templates, ...)
    └ resource_managed     → Managed resources (less, ...)
    └ src_managed          → Generated sources (templates, ...)

参考文献:Anatomy of a Play application

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值