2

我有一个使用 sbt 的 Scala 项目。它在 Eclipse 下运行得非常好,但是,尝试在 sbt 下运行它(sbt 'run mount 1440'——包括我需要的参数)会导致ClassNotFoundException——它找不到jnr.ffi.provider.jffi.NativeClosureProxy类。但是,运行sbt 'last run'显示该jnr-ffi-2.0.3.jar文件(包括所述类)实际上包含在类路径中。关于发生了什么的任何建议?

github 上可用的资源:https ://github.com/FileJunkie/vkfs

4

1 回答 1

1

您的构建 sbt 无效。

首先,您需要在libraryDependecys 之间有空行。

lazy val root = (project in file(".")).
  settings(
    name := "vkfs",
    version := "1.0",
    scalaVersion := "2.11.7"
  )

libraryDependencies += "org.scalaj" %% "scalaj-http" % "1.1.6"

libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.2.11"

libraryDependencies += "com.github.serceman" % "jnr-fuse" % "0.1"

其次,无法解析依赖“com.github.serceman”。这意味着要么

总而言之,Eclipse 似乎会自动执行某些操作,因此您的程序会运行。当涉及到您时build.sbt,它无效(缺少空行)并且无法正确解决依赖关系。我想知道,你怎么能开始通过sbt 'run mount 1440'

更正空行并运行 sbt 'run mount 1440' 我得到

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
[info] Set current project to vkfs (in build file:/home/.../IdeaProjects/vkfs/)
[info] Updating {file:/home/.../IdeaProjects/vkfs/}root...
[info] Resolving com.github.serceman#jnr-fuse;0.1 ...
[warn]  module not found: com.github.serceman#jnr-fuse;0.1
[warn] ==== local: tried
[warn]   /home/.../.ivy2/local/com.github.serceman/jnr-fuse/0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/com/github/serceman/jnr-fuse/0.1/jnr-fuse-0.1.pom
[info] Resolving jline#jline;2.12.1 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.github.serceman#jnr-fuse;0.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
sbt.ResolveException: unresolved dependency: com.github.serceman#jnr-fuse;0.1: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:213)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
[ ... truncated ... ]

编辑(关于来自 jcenter 的依赖)

将以下行添加到您的 build.sbt(记住额外的空行)

resolvers += Resolver.jcenterRepo

将 jcenter 添加到您的解析器列表中。

编辑 2

Resolver.jcenterRepo 在 SBT 0.13.5 中不可用,因此

resolvers += "jcenter" at "https://jcenter.bintray.com/"

是必须的。

成功编译并运行后,相关错误为

java.lang.RuntimeException: java.lang.NoClassDefFoundError: jnr/ffi/provider/jffi/NativeClosureProxy
at jnr.ffi.provider.jffi.NativeClosureProxy.newProxyFactory(NativeClosureProxy.java:220)

最后结果

v 0.1 中的库“com.github.serceman”似乎有问题,因为它无法通过反射正确实例化某些类。

解决方案

问题通过添加fork in run := true解决build.sbt

于 2015-11-01T13:16:32.313 回答