我想要的是链接到外部本地库,但不希望将它们包含在最终的jar中。
在build.sbt
中unmanagedClasspath in Compile ++= (file("/usr/local/lib/spark/jars") ** "*.jar").classpath
show compile:compile::unmanagedClasspath
的结果,与show compile:run::unmanagedClasspath
相同
[info] * Attributed(/usr/local/lib/spark/jars/ivy-2.4.0.jar)
[info] * Attributed(/usr/local/lib/spark/jars/spark-core_2.11-2.2.0.jar)
[info] * Attributed(/usr/local/lib/spark/jars/spire_2.11-0.13.0.jar)
[info] * Attributed(/usr/local/lib/spark/jars/javax.inject-1.jar)
[info] * Attributed(/usr/local/lib/spark/jars/protobuf-java-2.5.0.jar)
[info] * Attributed(/usr/local/lib/spark/jars/parquet-encoding-1.8.2.jar)
and many other...
compile
工作正常,但run
显示此错误
[info] Packaging /home/tansei/research/aclimdb/target/scala-2.12/aclimdb_2.12-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Running (fork) aclimdb.MyLogisticRegression
[error] Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/sql/SparkSession$
[error] at aclimdb.MyLogisticRegression$.main(MyLogisticRegression.scala:8)
[error] at aclimdb.MyLogisticRegression.main(MyLogisticRegression.scala)
[error] Caused by: java.lang.ClassNotFoundException: org.apache.spark.sql.SparkSession$
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error] ... 2 more
[error] java.lang.RuntimeException: Nonzero exit code returned from runner: 1
[error] at sbt.ForkRun.processExitCode$1(Run.scala:29)
[error] at sbt.ForkRun.run(Run.scala:38)
[error] at sbt.Defaults$.$anonfun$bgRunTask$5(Defaults.scala:1152)
[error] at sbt.Defaults$.$anonfun$bgRunTask$5$adapted(Defaults.scala:1147)
[error] at sbt.internal.BackgroundThreadPool.$anonfun$run$1(DefaultBackgroundJobService.scala:359)
[error] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] at scala.util.Try$.apply(Try.scala:209)
[error] at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:282)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error] at java.lang.Thread.run(Thread.java:745)
[error] (compile:run) Nonzero exit code returned from runner: 1
[error] Total time: 2 s, completed Oct 15, 2017 4:05:34 PM
我可能看起来很愚蠢地问这个问题,但这花了我很多时间,我不能接受这个。非常感谢您对此的任何帮助
答案 0 :(得分:0)
哎呀,在我再添加一行后,run
命令运行良好
unmanagedClasspath in Compile ++= (file("/usr/local/lib/spark/jars") ** "*.jar").classpath,
unmanagedClasspath in Runtime ++= (file("/usr/local/lib/spark/jars") ** "*.jar").classpath