Playframework 2.0 如何在play2中获取应用程序根路径?

Playframework 2.0 如何在play2中获取应用程序根路径?,playframework-2.0,Playframework 2.0,在play1中,我们可以通过以下方式获取应用程序路径: Play.applicationPath 如何在Play2中执行相同的操作?使用Scala API,您可以这样做,以便将java.io.File添加到应用程序: 导入play.api.play.current Play.application.path 在Java中: 导入play.play; Play.application().path(); 对于Play 2.5.x,应该是这样的。我保留与问题无关的东西。但是,对于其他事情,它应该

在play1中,我们可以通过以下方式获取应用程序路径:

Play.applicationPath

如何在Play2中执行相同的操作?

使用Scala API,您可以这样做,以便将
java.io.File
添加到应用程序:

导入play.api.play.current
Play.application.path
在Java中:

导入play.play;
Play.application().path();

对于Play 2.5.x,应该是这样的。我保留与问题无关的东西。但是,对于其他事情,它应该是方便的

package io

import javax.inject.Inject
import com.google.inject.Singleton
import play.Application
import play.api.Environment

@Singleton
class File @Inject()(environment: Environment, application: Application) {
    val home: java.io.File = application.path()
}

对于那些好奇的人,使用Java它的文件root=Play.application().path();如果我尝试在Java中使用Play.application().path(),就会得到一个“找不到符号”。导入什么?在scala play 2.2中,使用与current.path相同的导入