简体   繁体   English

播放2.3.x-“ build.sbt”中“ application.conf”中的应用名称

[英]Play 2.3.x - app name from “application.conf” in “build.sbt”

Using Play 2.1.xi was able to get the app name and version from the "conf/application.conf" in "project/build.scala" like this: 使用Play 2.1.xi可以从“ project / build.scala”中的“ conf / application.conf”获取应用名称和版本,如下所示:

import sbt._
import Keys._
import play.Project._
import com.typesafe.config._

object ApplicationBuild extends Build {
  val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()
  val appName = conf.getString("application.name")
  val appVersion = conf.getString("application.version")
 ....

I am migrating to Play 2.3.8 and I am trying to find a similar solution to get the name and version in "built.sbt". 我正在迁移到Play 2.3.8,并试图找到一个类似的解决方案来获取“ built.sbt”中的名称和版本。 I checked the migration guides and similar questions but none seems to work. 我检查了迁移指南和类似的问题,但似乎没有任何效果。

How do i do that? 我怎么做?

My project in Play 2.3.8 works well as below. 我在Play 2.3.8中的项目运作良好,如下所示。

import PlayKeys._
import com.typesafe.config._

val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()

name := conf.getString("application.name")

version := conf.getString("application.version")

I've create a couple of tests on my Play project (with version 2.3.8) and it looks like you have problem with locating this file. 我已经在Play项目(版本2.3.8)上创建了一些测试,看来您在查找此文件时遇到了问题。

When I try to read file application.conf (just for the purpose of testing) - it gives me FileNotFoundException, but suddenly Config silently ignore this problem. 当我尝试读取文件application.conf时 (仅出于测试目的)-它给了我FileNotFoundException,但突然Config默默地忽略了这个问题。 Anyway in my case everything works well ( conf/application.conf ) - and I was able retrieve any keys I want to. 无论如何,对于我来说一切都很好( conf / application.conf )-我能够检索到我想要的任何键。

So, I recommend to check if you could locate file properly - for example as first try you could replace path with absolute one, to check that parsing is working and then try to fix location problem. 因此,我建议检查是否可以正确定位文件-例如,首先尝试用绝对路径替换路径,以检查解析是否正常,然后尝试解决位置问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM