Run scala console with play 2.2 jars

a 夏天 提交于 2019-12-24 12:42:32

问题


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

回答1:


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.

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/'

Produces:

/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/')"

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/'



回答2:


@aleksey's answer works for me. I also find another way to do it.

Go to your project target folder

$ cd <your play project>/target/universal/stage/lib

Now, run this command.

$ scala -cp `ls -1 | tr "\\n" ":"`


来源:https://stackoverflow.com/questions/21978048/run-scala-console-with-play-2-2-jars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!