使用sbt构建Scala项目时,包括classpath上的非托管jar

时间:2019-04-12 15:50:13

标签: java scala apache-spark sbt sbt-assembly

我正在尝试建立一个旧项目。

该项目取决于在sparrow-1.0.jar

中找到的Java包。

我将jar复制到了lib_managed/jarslib目录中,但是在编译时我仍然遇到缺少的类路径错误。

project/SparkBuild.sbt包含对lib目录的引用

unmanagedJars in Compile <<= baseDirectory map { base => (base / "lib" ** "*.jar").classpath },

./lib

的内容
root@26eefef538b1:/sparrow/spark-sparrow# tree -D lib
lib
|-- jars
|   `-- sparrow-1.0-SNAPSHOT.jar
|-- sparrow-1.0-SNAPSHOT.jar
`-- sparrow.jar

但是,当我编译时,我仍然遇到相同的错误:

root@26eefef538b1:/sparrow/spark-sparrow# sbt/sbt package assembly
[info] Loading project definition from /sparrow/spark-sparrow/project/project
[info] Loading project definition from /sparrow/spark-sparrow/project
[info] Set current project to root (in build file:/sparrow/spark-sparrow/)
[info] Compiling 260 Scala sources and 16 Java sources to /sparrow/spark-sparrow/core/target/scala-2.9.3/classes...
[error] /sparrow/spark-sparrow/core/src/main/scala/spark/scheduler/sparrow/SparrowScheduler.scala:28: not found: object edu
[error] import edu.berkeley.sparrow.thrift.FrontendService
[error]        ^

从jar导入add classpath到项目中是否缺少命令行选项或其他配置?

使用scala 2.9.3针对sbt 0.12.3编译项目

我注意到我可以在类路径上使用jar运行scala并导入对象。

root@26eefef538b1:/sparrow/spark-sparrow# scala -cp $SPARROW_JAR                                                                                                                                                                                                                                                             
Welcome to Scala version 2.9.3 (OpenJDK 64-Bit Server VM, Java 1.7.0_201).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import edu.berkeley.sparrow.thrift.FrontendService
import edu.berkeley.sparrow.thrift.FrontendService

scala>

1 个答案:

答案 0 :(得分:0)

将lib目录和jar添加到子目录。 例如./core/lib/sparrow.jar似乎已经解决了问题