使用 play 2.2 jars 运行 Scala 控制台 [英] Run scala console with play 2.2 jars
问题描述
我看到有人在 Scala 控制台中使用 play api.如何将多个 play 的 jars 导入到 Scala 控制台?
I saw people using play apis in the scala console. How can I import multiple play's jars to scala console?
https://stackoverflow.com/a/17684559/772481
我试过这个命令,但没有用.
I tried this command, but it didn't work.
$ scala -cp /usr/local/Cellar/play/2.2.0/libexec/repository/local/com.typesafe.play/play_2.10/2.2.0/jars/*.jar
推荐答案
你的方法是对的.scala
REPL 理解所有 scalac
选项,所以 scala -cp
是正确的选项.但是,您必须在 Unix 上以冒号分隔的类路径中单独列出所有 jar.
Your approach was right. scala
REPL understands all scalac
options, so scala -cp
is the right option. However, you'll have to list all jars separately in the classpath separated by colon on Unix.
如果你像我一样懒惰并且不想拼出所有的 jar 文件,你可以使用这样的东西来构建类路径:
If you are lazy like me and don't want to spell out all jar files you can use something like this to build the classpath:
ls -1 ~/.ivy2/cache/com.typesafe/config/jars/config-1.0.* | tr '\n' ':' | sed 's/:$/\n/'
产生:
/home/alex/.ivy2/cache/com.typesafe/config/jars/config-1.0.0.jar:/home/alex/.ivy2/cache/com.typesafe/config/jars/config-1.0.2.jar
在您的原始命令中使用它:
Use it in your original command:
scala -cp "$(ls -1 /usr/local/Cellar/play/2.2.0/libexec/repository/local/com.typesafe.play/play_2.10/2.2.0/jars/*.jar | tr '\n' ':' | sed 's/:$/\n/')"
如果您想避免指定目录,请使用 find
而不是 ls
:
If you want to avoid specifying a directory use find
instead of ls
:
find ~/.ivy2/cache/com.typesafe/config/jars/ -name "*.jar" -exec echo {} \; | tr '\n' ':' | sed 's/:$/\n/'
这篇关于使用 play 2.2 jars 运行 Scala 控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!