当我开始使用以下项目时,以下代码可以正常工作 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)在您正在以(root用户?)身份执行应用程序的用户的配置文件中更改主目录
3)将丢失的文件复制到您的应用程序正在寻找文件的目录中
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句