2017-10-15 206 views
0

我究竟想要鏈接到外部本地庫,但不想將它們包含到最終jar中。項目編譯但無法運行,NoClassDefFoundError

在build.sbt結果的show compile:compile::unmanagedClasspath

unmanagedClasspath in Compile ++= (file("/usr/local/lib/spark/jars") ** "*.jar").classpath 

,相同的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 

我可以看傻問這個問題,但t他花了我很多時間,我無法接受這一點。非常感謝對本

回答

0

哎呀任何幫助後,我增加了一個路線,run命令運行正常

unmanagedClasspath in Compile ++= (file("/usr/local/lib/spark/jars") ** "*.jar").classpath, 
    unmanagedClasspath in Runtime ++= (file("/usr/local/lib/spark/jars") ** "*.jar").classpath 
相關問題