cannot add a jar to scala repl with the :cp command

If I issue:

$ scala -classpath poi-3.9/poi-3.9-20121203.jar 

scala> import org.apache.poi.hssf.usermodel.HSSFSheet
import org.apache.poi.hssf.usermodel.HSSFSheet

Everything works ok, but if instead I issue:

$ scala

scala> :cp poi-3.9/poi-3.9-20121203.jar
Added '/home/sas/tmp/poi/poi-3.9/poi-3.9-20121203.jar'.  Your new classpath is:
".:/home/sas/tmp/poi/poi-3.9/poi-3.9-20121203.jar"
Nothing to replay.

scala> import org.apache.poi.hssf.usermodel.HSSFSheet
<console>:7: error: object apache is not a member of package org
       import org.apache.poi.hssf.usermodel.HSSFSheet
                  ^

Am I missing something?


似乎没有人提到这一点,但正确的解决方案是使用:require命令:

scala> :require foo.jar
Added 'foo.jar' to classpath.

Another way to get jar files imported, in this case by default, is to add links in $SCALA_HOME/lib to the jar files of interest. Then every time you enter REPL, such linked jars will be uploaded.

For instance, for poi-3.9-20121203.jar , consider

(cd $SCALA_HOME/lib && ln -s full_path_to_poi_jar/poi-3.9-20121203.jar)

As noted in the comments, this is a known issue. You could use an alternative REPL implementation such as Ammonite.

链接地址: http://www.djcxy.com/p/73262.html

上一篇: SERVER ['REMOTE

下一篇: 不能使用:cp命令向scala repl添加jar