如何从PlayFramework中的Java代码访问SBT设置? [英] How to access SBT settings from Java code in PlayFramework?

查看:77
本文介绍了如何从PlayFramework中的Java代码访问SBT设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PlayFramework应用程序,并且build.sbt中有一个nameversion.

I have a PlayFramework application, and there is a name and version in the build.sbt.

如果我运行播放控制台,则可以通过键入nameversion来访问此信息.

If I run the play console, I can access this information by typing name or version.

如何从应用程序内的Java代码获取此信息?我似乎在Play.application()中找不到任何有用的方法,而且在文档中也找不到.

How can I get this information from Java code inside the application? I can't seem to find any useful methods in Play.application() and I have not been able to find this in the documentation.

推荐答案

为此,您可以使用SBT插件 BuildInfo :

For this you can use the SBT plugin BuildInfo:

添加到project/plugins.sbt:

Add to project/plugins.sbt:

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.5")

并构建.sbt:

buildInfoSettings

sourceGenerators in Compile <+= buildInfo

buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion)

buildInfoPackage := "hello"

现在您可以使用静态方法访问构建信息:

Now you can access the build information with static methods:

package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

public class Application extends Controller {

    public static Result index() {
        return ok(hello.BuildInfo.name());//the name of the application as output
    }

}

这篇关于如何从PlayFramework中的Java代码访问SBT设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆