Scala:尝试让 log4j 工作
Scala 新手在这里(这是我使用它的第二天)。我想让 log4j 日志记录在我的 Scala 脚本中工作。脚本和结果如下,对于出了什么问题有什么想法吗?
[sean@ibmp2 pybackup]$ cat backup.scala import org.apache.log4j._ val log = LogFactory.getLog() log.info("started backup") [sean@ibmp2 pybackup]$ scala -cp log4j-1.2.16.jar:. backup.scala /home/sean/projects/personal/pybackup/backup.scala:1: error: value apache is not a member of package org import org.apache.log4j._ ^ one error found
Scala newb here (it's my 2nd day of using it). I want to get log4j logging working in my Scala script. The script and the results are below, any ideas as to what's going wrong?
[sean@ibmp2 pybackup]$ cat backup.scala import org.apache.log4j._ val log = LogFactory.getLog() log.info("started backup") [sean@ibmp2 pybackup]$ scala -cp log4j-1.2.16.jar:. backup.scala /home/sean/projects/personal/pybackup/backup.scala:1: error: value apache is not a member of package org import org.apache.log4j._ ^ one error found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在Windows下重现它:'-classpath'的分隔符必须是';'那里(不是“:”)。你使用的是 cygwin 还是某种 unix 模拟器?
但是 Scala 脚本可以在类路径中没有当前目录的任何地方工作。尝试使用:
$ scala -cp log4j-1.2.16.jar backup.scala
JFI:LogFactory 是 slf4j 库(不是 log4j)的一类。
更新
另一种可能的情况:类路径中的 jar 损坏,可能是在下载或其他过程中。 Scala 解释器仅报告包中不可用的成员。
需要检查 jar 文件的内容:
I reproduce it under Windows: delimiter of '-classpath' must be ';' there (not ':'). Are you use cygwin or some sort of unix emulator?
But Scala script works anywhere without current dir in classpath. Try to use:
$ scala -cp log4j-1.2.16.jar backup.scala
JFI: LogFactory is a class of slf4j library (not log4j).
UPDATE
Another possible case: broken jar in classpath, maybe during download or something else. Scala interpreter does report only about unavailable member of the package.
Need to inspect content of the jar-file:
您是否记得将 log4j.jar 放入您的类路径中?
Did you remember to put log4j.jar in your classpath?
当开始使用 Eclipse 进行 Scala 开发时遇到类似的问题,进行干净的构建解决了该问题。
猜测 Scala 工具还不成熟等。
Had Similar issue when started doing Scala Development using Eclipse, doing a clean build solved the problem.
Guess the Scala tools are not matured et.
您可以尝试使用 Configgy,而不是直接使用 log4j。这是使用 log4j 以及配置文件的 Scala Way™。它还可以与 SBT 和 Maven 很好地配合。
Instead of using log4j directly, you might try using Configgy. It's the Scala Way™ to work with log4j, as well as configuration files. It also plays nicely with SBT and Maven.
我自己提出并回答了这个问题,看看:
I asked and answered this question myself, have a look: