Scala class path mixup java.lang.NoClassDefFoundError
I'm trying to do something in Scala with apparat library. The library is in /Applications/apparat. Compilation happens OK, imports are OK, but I still get this error when I run it.
scalac -classpath /Applications/apparat/\* SimpleObject.scala
scala -cp . SimpleObject hello.swf
java.lang.NoClassDefFoundError: apparat/utils/TagContainer$
Script:
import apparat.utils.TagContainer
object SimpleObject 开发者_如何学运维{
def main(args : Array[String]) : Unit = {
val tags = TagContainer.fromFile( args(0) )
}
}
I'm pretty sure I miss something either when compiling or when running it. If I use command line interpreter then the script works fine and I don't get any erros. For example can do this:
scala -cp /Applications/apparat/\*
Welcome to Scala version 2.8.0.RC3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import apparat.utils.TagContainer
import apparat.utils.TagContainer
scala> val tag = TagContainer.fromFile("hello.swf")
tag: apparat.utils.TagContainer = apparat.utils.TagContainer@533790eb
Figured it. Need to put current directory into the -cp (:.) as Daniel says when compiling. Also, when running the -cp has to point to same class path.
scala -classpath /Applications/apparat/\*:. SimpleObject hello.swf
though I thought wild cards were not allowed in class paths.
精彩评论