0
votes

I am developing a chat bot using IBM Watson conversation. When I build the project and run, it gives null in inputStream in the RequestUtils.java class in the java-sdk/conversation. but when I run it from the ide it works.

 InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties");

I noticed that properties file is not inside the jar. How to add this properties file to the jar when it is being built? What could be the possible cause? Any help is appreciated. Thanks.

P.S:scehema of the classes are as follows

parent
project1
project2
Maven Dependencies
|-conversation-3.5.3.jar
| |-package1
| |-packeage2
| |-META-INF
|-core-3.5.3.jar
  |-package1
  |-packeage2
  |  |-RequestUtils.class
  |-META-INF 
  |-version.properties   
1
can you provide schema of your classes and the version.properties file in your project? - STaefi
@Dimuth-Ruwantha can you open an issue in the repository? github.com/watson-developer-cloud/java-sdk I can work on it and update this once it's working - German Attanasio
@German Attanasio thank you for the quick response. I opened an issue in the following link github.com/watson-developer-cloud/java-sdk/issues/586 - Dimuth Ruwantha

1 Answers

1
votes

I fixed it by my own. the thread will inherit its context classloader from its parent Thread. If you don't do anything at all in the entire application, all Threads will end up with the system classloader as their context classloader. So I set the contextClassLoader on my own for the current thread as follows.

ClassLoader classLoader = MyClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader( classLoader );

now it works fine.