You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过SBT为Play应用设置自定义控制台横幅

可以修改Play Framework启动横幅,具体实现方法如下:

方法1:在build.sbt中直接配置

在项目根目录的build.sbt文件里添加以下代码,自定义你的横幅内容:

onLoadMessage := {
  val customBanner = """
    [info]   *************************
    [info]   *  我的自定义Play应用  *
    [info]   *************************
    [info]   
    """
  // 可选择拼接原有版本信息和提示,也可完全替换
  customBanner + s"[info] Version ${play.core.PlayVersion.current} running Java ${System.getProperty("java.version")}" + "\n" +
  "[info] \n[info] Play is run entirely by the community. Please consider contributing and/or donating:" + "\n" +
  "[info] https://www.playframework.com/sponsors"
}

方法2:创建自定义sbt插件(适合多项目复用)

  1. 在项目的project目录下新建CustomBannerPlugin.scala文件,内容如下:
import sbt._
import Keys._

object CustomBannerPlugin extends AutoPlugin {
  override def trigger = allRequirements
  override def projectSettings = Seq(
    onLoadMessage := {
      val customBanner = """
        [info]   ┌─────────────────────────┐
        [info]   │  自定义Play应用横幅    │
        [info]   └─────────────────────────┘
        [info]   
        """
      customBanner + s"[info] Version ${play.core.PlayVersion.current} running Java ${System.getProperty("java.version")}" + "\n" +
      "[info] \n[info] Play is run entirely by the community. Please consider contributing and/or donating:" + "\n" +
      "[info] https://www.playframework.com/sponsors"
    }
  )
}
  1. 该插件为AutoPlugin类型,无需额外配置引用会自动生效。

关键说明

  • 横幅内容里的[info]前缀需保留,确保输出和sbt日志格式统一。
  • 若不需要保留原有版本信息和捐赠提示,可直接在onLoadMessage中编写完整自定义内容,无需拼接原有内容。

内容的提问来源于stack exchange,提问作者Anish B.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 01:57:15