Scala 类路径混合 java.lang.NoClassDefFoundError
我正在尝试使用 Apparat 库在 Scala 中做一些事情。该库位于 /Applications/apparat 中。编译正常,导入正常,但运行时仍然出现此错误。
scalac -classpath /Applications/apparat/\* SimpleObject.scala
scala -cp . SimpleObject hello.swf
java.lang.NoClassDefFoundError: apparat/utils/TagContainer$
脚本:
import apparat.utils.TagContainer
object SimpleObject {
def main(args : Array[String]) : Unit = {
val tags = TagContainer.fromFile( args(0) )
}
}
我很确定我在编译或运行时错过了一些东西。如果我使用命令行解释器,那么脚本可以正常工作并且不会出现任何错误。例如可以这样做:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了。需要将当前目录放入 -cp (:.) 中,如 Daniel 在编译时所说。另外,运行时 -cp 必须指向相同的类路径。
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.
尽管我认为类路径中不允许使用通配符。
though I thought wild cards were not allowed in class paths.