当我使用 play start
启动项目时,下面的代码工作正常
object LogFile {
implicit val formats = DefaultFormats
private var fileInput = new FileInputStream("./conf/log4j.properties");
private val properties = new Properties
properties.load(fileInput);
def test(head: String, data: String) {
System.setProperty("my.log", "scala.txt")
PropertyConfigurator.configure(properties)
val log = Logger.getLogger(head)
log.error(data)
}
}
但是当我使用sudo/home/ubuntu/play/play dist
并运行我得到的结果:
[error] play - Cannot invoke the action, eventually got an error:
java.io.FileNotFoundException: ./conf/log4j.properties (No such file or directory)
我做错了什么?
我正在使用 Scala 2.10 和 play Framework 2.2
最佳答案
您缺少 Log4j 属性文件
./conf/log4j.properties
您可能丢失了该文件:
/home/ubuntu/project/conf/log4j.properties
sudo
命令更改您正在执行的用户。所以新用户可能有不同的环境变量。
注意:project
是应用程序名称。
此外,您还使用相对路径 ./conf/log4j.properties
,该路径的根目录将在运行时根据您正在执行的主目录进行解析。
可能的解决方案:
1)不要使用相对路径,而使用绝对路径
2) 更改正在执行的用户的配置文件中的主目录 您的应用程序作为(根用户?)
3) 将丢失的文件复制到应用程序正在查找该文件的目录
关于使用 play dist 出现 java.io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325478/