尽管设置了CLASSPATH或使用-classpath选项,为什么Scala脚本找不到类?

时间:2013-07-01 12:50:32

标签: scala

我有以下Scala(2.10.1)脚本:

#!/bin/bash

export CLASSPATH=${WORKSPACE}/build/classes/main:${WORKSPACE}/build/libs/setter-for-catan.jar

exec ${SCALA_HOME}/bin/scala "$0" "$@" 2>&1
!#

import sfc.board.SmallBoard

$ cd ${WORKSPACE}
$ find build/classes/main -name 'SmallBoard*.class'
build/classes/main/sfc/board/SmallBoard$$anonfun$1.class
build/classes/main/sfc/board/SmallBoard$$anonfun$2.class
build/classes/main/sfc/board/SmallBoard$$anonfun$3.class
build/classes/main/sfc/board/SmallBoard$$anonfun$4.class
build/classes/main/sfc/board/SmallBoard$$anonfun$5.class
build/classes/main/sfc/board/SmallBoard$$anonfun$6.class
build/classes/main/sfc/board/SmallBoard$.class
build/classes/main/sfc/board/SmallBoard.class
$ jar tvf build/libs/setter-for-catan.jar | grep SmallBoard
  1272 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$$anonfun$1.class
  1272 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$$anonfun$2.class
  1276 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$$anonfun$3.class
  1581 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$$anonfun$4.class
  1103 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$$anonfun$5.class
  1527 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$$anonfun$6.class
  8097 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard$.class
  3722 Sun Jun 30 20:40:54 EDT 2013 sfc/board/SmallBoard.class

然而脚本没有找到sfc包而不是类:

$ ./setter-for-catan.scala 
./setter-for-catan.scala:10: error: not found: object sfc
import sfc.board.SmallBoard
       ^
one error found

发生了什么以及需要采取哪些措施来解决问题?

1 个答案:

答案 0 :(得分:1)

使用scala -cp ${CLASSPATH},而不是scala -classpath ${CLASSPATH}