2

We have a properties file, kafka.properties located under src/main/resources and the following two snippets of code.

1: ClassLoader.getSystemClassLoader().getResourceAsStream("kafka.properties");

2: this.getClass().getClassLoader().getResourceAsStream("kafka.properties");

Both of these code snippets work fine on my local machine. However, whenever we deploy our application onto our cloud server only the second code snippet works.

I'm assuming it's something to do with the fact that on our server we are running a zipped .jar file, whereas when I run it locally IntelliJ compiles it in memory and uses the filesystem for lookup.

I'm curious what causes this and what the specific differences are between these two methods?

Adam
  • 1,724
  • 13
  • 16
  • Did you read the JavaDocs for those methods ([one](https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getClassLoader()) and [two](https://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#getSystemClassLoader()))? What did you not understand? – Michael Mar 06 '19 at 11:15
  • 1
    *"I'm assuming it's something to do with ..."* - The difference is presumably that Kafka is creating a new classloader *dynamically* when it is run on the server. You can get some clues by printing out what the two ways of getting a class loader give you ... in the two contexts. But clearly, the 2nd way to do it is the way that works. – Stephen C Mar 06 '19 at 11:25

0 Answers0