WAS Liberty profile - Read property using ClassLoader.getSystemResourceAsStream

Bruno :

We are migrating our application from WAS 6.1 to Liberty. Our application uses third party jars that read property files byInputStream is = ClassLoader.getSystemResource("myproperty.properties"). In WAS 6.1, we set server classpath to the location of myproperty.properties. We tried the below approaches to set classpath in Liberty, but nothing works

Approach 1: Set the below in jvm.options (D:\ConfigFiles\DEV\ - path containing myproperty.properties)

-Djava.class.path=D:\\ConfigFiles\\DEV\\

Approach 2: Setting the classloader in server.xml,

<library id="config">
 <folder dir="${server.config.dir}/config/" includes="*.properties" scanInterval="5s"/>
</library>

<enterpriseApplication id="applicationEAR" location="application.ear" name="application">
 <classloader privateLibraryRef="config"/>
</enterpriseApplication>

Please let us know if there is any other ways to override/set classpath in Liberty profile?

Andy McCright :

Try setting this property in jvm.options (instead of -Djava.class.path=path/to/propertyDir):

-Xbootclasspath/a:path/to/propertyDir

This will append the path of the property directory (containing your resource file) to the JVM's bootstrap classpath. Because this is an append, it should also work in Java 9+ (some related options have been removed in Java 9).

I suspect that the reason -Djava.class.path=... doesn't work is that the JVM gets the classpath from the WLP server script - so the system property is essentially applied too late in the startup of the server JVM.

You might also be able to put the properties file(s) in your JVM's lib/ext directory, but I haven't tested that. The -Xbootclasspath/a:path approach works for me on Mac - I assume it will also work on Windows.

HTH, Andy

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=92124&siteId=1