0

I have a very simple project that consists of a .scala file, a build.sbt file, and a /lib folder with a single .jar in it. My scalaVersion is set to 2.10.5 (for backwards compatibility) and I ran sbt compile, and sbt downloads .jars for scala-2.10 and scala-swing. So it seems like that part is working...

When I do sbt run I get a runtime error:

[info] Running GuiProgramOne 
[error] (run-main-0) java.lang.NoClassDefFoundError: scala/collection/GenTraversableLike$class
java.lang.NoClassDefFoundError: scala/collection/GenTraversableLike$class
    at scala.swing.RefSet.<init>(Publisher.scala:167)
    at scala.swing.Publisher$$anon$1.<init>(Publisher.scala:34)
    at scala.swing.Publisher$class.$init$(Publisher.scala:34)
    at scala.swing.Window.<init>(Window.scala:25)
    at scala.swing.Frame.<init>(RichWindow.scala:77)
    at scala.swing.MainFrame.<init>(MainFrame.scala:19)
    at UI.<init>(UI.scala:3)
    at GuiProgramOne$.main(UI.scala:11)
    at GuiProgramOne.main(UI.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableLike$class
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at scala.swing.RefSet.<init>(Publisher.scala:167)
    at scala.swing.Publisher$$anon$1.<init>(Publisher.scala:34)
    at scala.swing.Publisher$class.$init$(Publisher.scala:34)
    at scala.swing.Window.<init>(Window.scala:25)
    at scala.swing.Frame.<init>(RichWindow.scala:77)
    at scala.swing.MainFrame.<init>(MainFrame.scala:19)
    at UI.<init>(UI.scala:3)
    at GuiProgramOne$.main(UI.scala:11)
    at GuiProgramOne.main(UI.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)

Directory structure:

.
├── build.sbt
├── GUI.class
├── GUI$.class
├── lib
│   └── scala-swing-2.9.1.jar
├── project
│   └── target
│       └── config-classes
│           ...
├── target
│   └── streams
│       ...
└── GUI.scala

build.sbt:

lazy val root = (project in file(".")).
  settings(
    inThisBuild(List(
      scalaVersion := "2.10.5"
    )),
    name := "Game of Life",
    libraryDependencies ++= Seq(
      "org.scala-lang" % "scala-swing" % "2.9.1"
    )
  )

code: http://otfried.org/scala/index_28.html

4

1 回答 1

0

your scala version is 2.10.5 and hence the scala-swing version should be scala-swing-2.10.5.jar. so you should change your build.sbt file as shown below

libraryDependencies ++= Seq(
      "org.scala-lang" % "scala-swing" % scalaVersion.value
    )

and you dont need the scala-swing-2.9.1.jar in your lib directory since you already declaring the dependency in build.sbt. so remove it to avoid any potential collisions between the managed and un-managed dependencies.

于 2017-02-23T19:20:53.783 回答