2

I have a Scala project using sbt. It runs perfectly well under Eclipse, however, trying to run it under sbt (sbt 'run mount 1440' — including the parameters I need) leads to a ClassNotFoundException — it can not find jnr.ffi.provider.jffi.NativeClosureProxy class. However, running sbt 'last run' shows me that jnr-ffi-2.0.3.jar file (which includes the said class) is actually included in the classpath. Any suggestions on what's happening?

Sources available on github: https://github.com/FileJunkie/vkfs

Ilia Ershov
  • 25
  • 1
  • 7
  • You should include the relevant bits of your code here, so it is useful to other visitors who may encounter a similar issue in the future – Lima Nov 01 '15 at 12:29

1 Answers1

1

Your build sbt is invalid.

First, you need to have empty lines between the 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"

Second, the dependency "com.github.serceman" can not be resolved. This means either that

So in summary, it seems that Eclipse does something automatically, so your program runs. When it comes to your build.sbt it is not valid (empty lines missing) and does not resolve dependencies properly. I wonder, how you could start via sbt 'run mount 1440' at all.

After correcting the empty lines and running sbt 'run mount 1440' I obtain

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 ... ]

Edit (concerning dependency from jcenter)

Add the following line to your build.sbt (remember extra empty line)

resolvers += Resolver.jcenterRepo

to add jcenter to your resolver list.

Edit 2

Resolver.jcenterRepo is not available in SBT 0.13.5, thus

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

is required.

After successful compilation and run the relevant error is

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

Final result

The library "com.github.serceman" in v 0.1 seems to be problematic, as it can not properly instantiate some class via reflection.

Solution

Problem solved by adding fork in run := true to build.sbt.

Ilia Ershov
  • 25
  • 1
  • 7
Martin Senne
  • 5,939
  • 6
  • 30
  • 47
  • Thanks for noticing the lack of empty lines between `libraryDependencies` lines, but it changed nothing. As for `jnr-fuse`, it is available from jcenter repository (in the manual you posted a link to it is said that this repo is available by default), and my sbt successfully resolved this dependency after I cleaned up the cache. The `ClassNotFoundException` which I mentioned is only reachable in runtime, so since jnr-fuse isn't resolvable on your machine, you could not reach that point where I encounter this exception. – Ilia Ershov Nov 01 '15 at 14:31
  • No, not true. The repo jcenter is not added by default. Instead it is a predefined variable as doc states `Resolver.jcenterRepo`. Will edit my post ... – Martin Senne Nov 01 '15 at 14:54
  • Hm. I wonder why does my sbt resolve this dependency at all then. However, adding `resolvers += Resolver.jcenterRepo` to `build.sbt`, once again, changes nothing for me. – Ilia Ershov Nov 01 '15 at 14:58
  • How are you starting sbt? Just start sbt via `sbt` from bash/shell and call then `run mount 1440` in interactive sbt console. – Martin Senne Nov 01 '15 at 15:00
  • Running `sbt 'run mount 1440'` and using the way you described leads to the same results - no dependency issues, all necessary file are in classpath (checking with `last run` command), including `jnr-ffi-2.0.3.jar`, and this the exact file which contains the class which can't be found under sbt. – Ilia Ershov Nov 01 '15 at 15:03
  • See my edit! Problem is a bad library "com.github.serceman". Contact the author of the lib, as it has nothing to do with SBT and build configuration. – Martin Senne Nov 01 '15 at 16:33
  • Why it runs under Eclipse is still unclear. How have you added it under eclipse? (I mean installation of the lib). – Martin Senne Nov 01 '15 at 16:36
  • No, I just used sbt-eclipse plugin to generate eclipse project. Thank you for you time, will contact the library author. – Ilia Ershov Nov 01 '15 at 16:39
  • 1. Do not hesitate to "reward" the time effort ;) 2. If it really has **run successfully with Eclipse**, this means there is a solution. So maybe Eclipse provides some libraries that are expected for the serceman lib to run. Try to clarify, what the library expects. – Martin Senne Nov 01 '15 at 16:47