我有一个Java应用程序,我写成Spark Streaming作业,它需要一些文本资源,这些文本资源包含在jar中的资源目录中(使用默认的Maven目录结构体)。使用单元测试我没有问题访问这些文件,但是当我用spark-submit运行我的程序时,我得到一个FileNotFoundException。如何在使用spark-submit运行时访问JAR中类路径上的文件?从Apache Spark访问JAR资源目录中的文件流式上下文
我目前使用的访问我的文件中的代码看起来大致是这样的:
InputStream input;
try {
URL url = this.getClass().getClassLoader().getResource("my file");
if (url == null) {
throw new IOException("file does not exist");
}
String path = url.getPath();
input = new FileInputStream(path);
} catch(IOException e) {
throw new RuntimeException(e);
}
感谢。
请注意,这不是Reading a resource file from within jar(建议)的副本,因为此代码在本地运行时工作。它仅在Spark群集中运行时失败。
这不是火花相关或流,这是普通的Java代码。 – Shankar
http://stackoverflow.com/questions/20389255/reading-a-resource-file-from-within-jar – Shankar
可能的重复。上述工作在正常运行时。当使用spark-submit运行时失败。因此,火花问题。 – Peter