为什么在运行由sbt打包的jar文件时出现此jni错误?

时间:2018-10-30 14:04:05

标签: scala sbt

我有一个可以在IDE中正常运行的项目,但是由于某些原因,我无法从命令行运行打包的jar。

这是我的build.sbt的样子:

import sbt.io.Using

name := "bigdata-mx-2"

version := "0.1"

scalaVersion := "2.12.7"

libraryDependencies ++=Seq(
  "junit" % "junit" % "4.10" % Test,
  "org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test,
  "org.apache.parquet" % "parquet-avro" % "1.10.0",
  "org.apache.hadoop" % "hadoop-common" % "3.1.1"
)

packageOptions in (Compile, packageBin) +=  {
  val file = new java.io.File("META-INF/MANIFEST.MF")
  val manifest = Using.fileInputStream(file)( in => new java.util.jar.Manifest(in) )
  Package.JarManifest( manifest )
}

我做sbt compile, package并得到了一个jar文件。当我通过java -jar myjar.jar运行它时,我得到:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function0
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: scala.Function0
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

为什么会这样?我该如何解决这个问题?

0 个答案:

没有答案