1

I am running on WebSphere Liberty 17.0.0.4. Deployed a web application and custom authentication module which is located under {wlp_install_dir}/lib directory. And that jar file is marked as library in server.xml file. Here is how it looks in server.xml

<library id="CustomLoginModuleLib">
    <fileset dir="${wlp.lib.dir}" includes="custom_auth.jar"/>
</library>

Now the thing is, I want to use .properties file located inside custom_auth.jar file to the web application.

Have tried following code snippet to access:

this.getClass().getResourceAsStream("location/of/package/file.properties");

ClassLoader.getSystemResourceAsStream("location/of/package/file.properties");

But, neither works.

Any idea how can we access properties file located in library jar file.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
Parth Bhagat
  • 509
  • 1
  • 11
  • 24
  • 1
    Are you calling `this.getClass().getResourceAsStream()` from within the web application, or from within the library? Or, have you tried getting a class from the library and then calling `getResourceAsStream()` from it instead of from `this.getClass()`? – kaczyns Apr 26 '18 at 15:36

1 Answers1

4

Please see my response to this same question on dwAnswers at: https://developer.ibm.com/answers/questions/444708/how-to-access-properties-file-located-in-library-j.html

To summarize the answer from there:

(1) I would never recommend putting user-provided JAR files in the {wlp_install_dir}/lib directory - that dir is only intended for IBM-provided JAR files. Instead, I would suggest putting your custom_auth.jar in your server directory or in a shared directory.

(2) You will need to associate the shared library with your application(s) like so:

 <application location ="{appName}.war"> <!-- or {appName}.ear -->
    <classloader commonLibraryRef="CustomLoginModuleLib" />
 </application>

Depending on your needs, you can use a commonLibraryRef (as shown) or a privateLibraryRef. More info on shared libraries can be found here: https://www.ibm.com/support/knowledgecenter/SSD28V_9.0.0/com.ibm.websphere.wlp.core.doc/ae/cwlp_sharedlibrary.html

(3) As for loading the file in the Java code, your first line will work - assuming that this refers to an instance of a class in your application. I also assumes that the path you pass to the getResourceAsStream method is the same as the path to the file inside the library JAR.

Hope this helps, Andy

Andy McCright
  • 1,273
  • 6
  • 8