0

Developed a rest service which uses third party jars. Reviewing their code I found that they are using ClassLoader.getSystemResource("log4j.properties") to retrieve the data. This code returns null and henceforth I get null pointer exception always. The same code if I deploy in websphere 8.5.5.7 and set server classpath it is working fine. Since I am using Liberty in my local machine this is not retrieving the path.

I also tried setting classloader in server.xml but no use.

<library id="config">
  <folder dir="/properties/dev/" includes="*.properties" scanInterval="5s"/>
</library>

<enterpriseApplication id="AbcEAR"location="AbcEAR.ear" name="AbcEAR">
  <classloader privateLibraryRef="config"/>
</enterpriseApplication>
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
Cts user
  • 21
  • 3

1 Answers1

0

Using ClassLoader.getSystemResource() will use the system classloader, which will only be able to see things from the JDK and whatever is on the classpath. Since Liberty does not use a traditional classpath and instead uses OSGi, the system loader will be of little use in Liberty from an application perspective.

Instead, use ClassLoader.getResource() from the thread context classloader, which will take into account the Liberty classloaders.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • Thanks Andy. As I said, I am using third party jars and I do not have access to update the code. I tried to find the class path and place the properties file but still received null. – Cts user Nov 15 '17 at 02:46
  • @Ctsuser have you tried adding configuring the JVM classpath in jvm.options to add /properties/dev? – Alasdair Nov 15 '17 at 03:24