我有一个可以在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
为什么会这样?我该如何解决这个问题?