Adding .jar's to classpath (Scala)

大憨熊 提交于 2019-12-03 09:55:38

You need to pass both classpath paths as a single argument.

Try this:

$ scalac -classpath "*.jar:dependencies/*.jar" PageRank.scala
$ scala -classpath "*.jar:dependencies/*.jar" PageRank
PageRankVertex(id=2, state=0.9999999999999997)
PageRankVertex(id=1, state=0.9999999999999997)

It worked for me.

It seems that depending on an installed version of Java, wildcards in classpath to include multiple JARs might or might not work. I found this trick elsewhere on StackOverflow (note that you can have as many folders after the 'echo' as you wish, separated by spaces):

scalac -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':')  PageRank.scala
scala -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':')  PageRank

for simplicity ,you can just use: scala -classpath $(echo *.jar dependencies/*.jar | tr ' ' ':') PageRank.scala

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