You can upload configuration files for custom jobs (Jar).
Take Kafka sink as an example. Two files (userData/kafka-sink.conf and userData/client.truststore.jks) need to be loaded.
Relative path: confPath = userData/kafka-sink.conf @Override public void open(Configuration parameters) throws Exception { super.open(parameters); initConf(); producer = new KafkaProducer<>(props); } private void initConf() { try { URL url = DliFlinkDemoDis2Kafka.class.getClassLoader().getResource(confPath); if (url != null) { LOGGER.info("kafka main-url: " + url.getFile()); } else { LOGGER.info("kafka url error......"); } InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(url.getFile()).getAbsolutePath())); props.load(new InputStreamReader(inputStream, "UTF-8")); topic = props.getProperty("topic"); partition = Integer.parseInt(props.getProperty("partition")); vaildProps(); } catch (Exception e) { LOGGER.info("load kafka conf failed"); e.printStackTrace(); } }
Absolute path: confPath = userData/kafka-sink.conf / path = /opt/data1/hadoop/tmp/usercache/omm/appcache/application_xxx_0015/container_xxx_0015_01_000002/userData/client.truststore.jks @Override public void open(Configuration parameters) throws Exception { super.open(parameters); initConf(); String path = DliFlinkDemoDis2Kafka.class.getClassLoader().getResource("userData/client.truststore.jks").getPath(); LOGGER.info("kafka abs path " + path); props.setProperty("ssl.truststore.location", path); producer = new KafkaProducer<>(props); } private void initConf() { try { URL url = DliFlinkDemoDis2Kafka.class.getClassLoader().getResource(confPath); if (url != null) { LOGGER.info("kafka main-url: " + url.getFile()); } else { LOGGER.info("kafka url error......"); } InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(url.getFile()).getAbsolutePath())); props.load(new InputStreamReader(inputStream, "UTF-8")); topic = props.getProperty("topic"); partition = Integer.parseInt(props.getProperty("partition")); vaildProps(); } catch (Exception e) { LOGGER.info("load kafka conf failed"); e.printStackTrace(); } }