![scala ide(eclipse)和sbt项目](https://linux22.com/image/1103677/scala%20ide%EF%BC%88eclipse%EF%BC%89%E5%92%8Csbt%E9%A1%B9%E7%9B%AE.png)
我正在使用最新版本的 scala ide eclipsehttp://scala-ide.org/
Scala IDE build of Eclipse SDK
Build id: 4.0.0-vfinal-20141216-1226-Typesafe
我有一个可以使用 sbt 从终端运行的项目:
donbeo@donbeo-HP-EliteBook-Folio-9470m:~/Applications/scala_workspace/progfun-quickcheck$ sbt
[info] Loading project definition from /home/donbeo/Applications/scala_workspace/progfun-quickcheck/project/project
[info] Loading project definition from /home/donbeo/Applications/scala_workspace/progfun-quickcheck/project
[info] Set current project to progfun-quickcheck (in build file:/home/donbeo/Applications/scala_workspace/progfun-quickcheck/)
> test
[info] + Heap.min1: OK, passed 100 tests.
[info] + Heap.min2: OK, passed 100 tests.
[info] + Heap.min3: OK, passed 100 tests.
[info] ! Heap.sort1: Falsified after 1 passed tests.
[info] > ARG_0: List("0")
[info] + Heap.minMeld: OK, passed 100 tests.
[info] Quic..........
我试图将该项目导入到 eclipse 中运行:
ickcheck$ sbt
[info] Loading project definition from /home/donbeo/Applications/scala_workspace/progfun-quickcheck/project/project
[info] Loading project definition from /home/donbeo/Applications/scala_workspace/progfun-quickcheck/project
[info] Set current project to progfun-quickcheck (in build file:/home/donbeo/Applications/scala_workspace/progfun-quickcheck/)
> eclipse
[info] About to create Eclipse project files for your project(s).
[info] Successfully created Eclipse project files for project(s):
[info] progfun-quickcheck
>
然后我将项目导入 eclipse。当我尝试从 eclipse 运行该项目时,出现以下错误:
WARNING: -p has been deprecated and will be reused for a different (but still very cool) purpose in ScalaTest 2.0. Please change all uses of -p to -R.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher$.main(ScalaTestLauncher.scala:20)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher.main(ScalaTestLauncher.scala)
Caused by: java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
at org.scalatest.tools.Runner$.argTooShort$1(Runner.scala:1010)
at org.scalatest.tools.Runner$.parseReporterArgsIntoConfigurations(Runner.scala:1024)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:627)
at org.scalatest.tools.Runner$.main(Runner.scala:573)
at org.scalatest.tools.Runner.main(Runner.scala)
... 6 more
我的理解是,我使用的 ecplise 版本应该有自己的 sbt 插件,所以也许这可以让事情变得更容易。
那么我怎样才能从 eclipse 运行该项目?
答案1
这个问题和那个问题不是很相似吗:https://stackoverflow.com/questions/26701992/exception-occurs-when-running-scala-test-from-eclipse? 错误完全相同。
解决方案是:
“检查你的类路径;特别是检查你所依赖的 scalatest 版本是否针对 scala 2.11 而不是 2.10 编译。”——作者 lmm。