1–files配置
spark2-submit \
--class xxx \
--master yarn \
--deploy-mode client \
--files /etc/hive/conf/test.properties \
spark-1.0-SNAPSHOT.jar
2.读取代码
方法一:
Properties properties = new Properties();
properties.load(new FileInputStream("test.properties"));
经过测试方法一,在local、yarn client、yarn cluster模式下driver都能读取到文件,所以使用这种方式
方法二:
Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"));
方法二 在yarn cluster模式下driver能读取到文件
方法三:
JavaRDD<String> stringJavaRDD = jsc.textFile(SparkFiles.get(path));
List<String> collect = stringJavaRDD.collect();
经过测试在local模式下可以读取到文件,但yarn模式读取不到,不清楚原因