在SBT下运行的应用程序无法从Classpath jar中找到一个类

时间:2015-11-01 12:16:54

标签: scala sbt jnr

我有一个使用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

1 个答案:

答案 0 :(得分:0)

你的构建sbt无效。

首先,您需要在libraryDependecy之间添加空行。

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来解决问题。