【发布时间】:2014-11-21 13:19:57
【问题描述】:
我有一个使用 Maven(作为 jar)构建并使用 spark-submit 脚本部署的 Spark Streaming 应用程序。应用项目布局遵循标准目录布局:
myApp
src
main
scala
com.mycompany.package
MyApp.scala
DoSomething.scala
...
resources
aPerlScript.pl
...
test
scala
com.mycompany.package
MyAppTest.scala
...
target
...
pom.xml
在DoSomething.scala 对象中,我有一个方法(我们称之为doSomething())尝试执行Perl 脚本——aPerlScript.pl(来自resources 文件夹)——使用scala.sys.process.Process 并传递两个脚本的参数(第一个是用作输入的二进制文件的绝对路径,第二个是生成的输出文件的路径/名称)。然后我打电话给DoSomething.doSomething()。
问题是我无法访问脚本,不是绝对路径、相对路径、getClass.getClassLoader.getResource、getClass.getResource,我在pom.xml 中指定了资源文件夹。我的尝试都没有成功。我不知道如何找到我放在 src/main/resources 中的东西。
我将不胜感激。
旁注:
- 我使用外部流程而不是 Spark 管道,因为在我的工作流程的这一步,我必须处理二进制文件作为输入和输出。
- 我正在使用 Spark-streaming 1.1.0、Scala 2.10.4 和 Java 7。我使用 Eclipse (Kepler) 中的“Maven install”构建 jar
- 当我使用
getClass.getClassLoader.getResource“标准”方法访问资源时,我发现实际的类路径是spark-submit脚本的路径。
【问题讨论】:
-
你能
gist.github.comScala 中访问静态资源的代码吗?您的问题似乎与 Spark 本身无关,而是关于如何在 Scala 中访问类路径上的静态资源的一般问题。请帮助我了解我错了多少。
标签: scala maven spark-streaming