ドキュメント

§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.13
    └ 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アーキテクチャパターンの各コンポーネントに対応する3つのパッケージがあります。

独自のパッケージ(例:app/servicesパッケージ)を追加できます。

**注意**: Playでは、controllersmodelsviewsというパッケージ名は単なる規則であり、必要に応じて変更できます(すべてにcom.yourcompanyというプレフィックスを付けるなど)。

LESSソースCoffeeScriptソースなどのコンパイル済みアセット用のオプションのディレクトリである`app/assets`もあります。

§public/ディレクトリ

publicディレクトリに格納されているリソースは、Webサーバーによって直接提供される静的アセットです。

このディレクトリは、画像、CSSスタイルシート、JavaScriptファイルの3つのサブディレクトリに分割されています。すべてのPlayアプリケーションの整合性を保つために、静的アセットをこのように整理する必要があります。

新しく作成されたアプリケーションでは、/publicディレクトリは/assets URLパスにマッピングされていますが、これを簡単に変更したり、静的アセットに複数のディレクトリを使用したりすることもできます。

§conf/ディレクトリ

confディレクトリには、アプリケーションの構成ファイルが含まれています。主な構成ファイルは2つあります。

アプリケーションに固有の構成オプションを追加する必要がある場合は、application.confファイルにオプションを追加することをお勧めします。

ライブラリに特定の構成ファイルが必要な場合は、confディレクトリの下に配置することをお勧めします。

§lib/ディレクトリ

libディレクトリはオプションであり、管理対象外のライブラリの依存関係、つまりビルドシステムの外部で手動で管理するすべてのJARファイルが含まれています。JARファイルをここにドロップするだけで、アプリケーションのクラスパスに追加されます。

§build.sbtファイル

プロジェクトのメインビルド宣言は、通常、プロジェクトのルートにある`build.sbt`にあります。

§project/ディレクトリ

projectディレクトリには、sbtビルド定義が含まれています。

§target/ディレクトリ

targetディレクトリには、ビルドシステムによって生成されたすべてのものが含まれています。ここに何が生成されるかを知っておくと便利です。

§典型的な.gitignoreファイル

生成されたフォルダーは、バージョン管理システムによって無視される必要があります。Playアプリケーションの典型的な.gitignoreファイルは次のとおりです。

logs
project/project
project/target
target
tmp
dist
.bsp
.cache
RUNNING_PID

§デフォルトのsbtレイアウト

sbtMavenで使用されるデフォルトのレイアウトを使用することもできます。このレイアウトを使用するには、レイアウトプラグインを無効にし、twirlテンプレートの明示的な監視を設定する必要があります。

// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

lazy val root: Project = (project in file("."))
  .enablePlugins(PlayScala)
  // Use sbt default layout
  .disablePlugins(PlayLayoutPlugin)

これにより、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.13
    └ cache
    └ classes              → Compiled class files
    └ classes_managed      → Managed class files (templates, ...)
    └ resource_managed     → Managed resources (less, ...)
    └ src_managed          → Generated sources (templates, ...)

**次へ: **Playコンソールの使用


このドキュメントに誤りを見つけましたか?このページのソースコードはこちらにあります。ドキュメントガイドラインを読んだ後、プルリクエストを送信してください。質問やアドバイスがありますか?コミュニティフォーラムにアクセスして、コミュニティとの会話を開始してください。