Robustly linking to libjvm.so

How to link to libjvm.so in a way that survives package updates?

There is a problem where some programs (the R library rJava in this case), cannot find libjvm.so due to some directory rearrangements. One proposed solution is to add its directory to ldconfig via a file in /etc/ld.so.conf.d/

See the StackOverflow solution for details:

The problem is that on Fedora, the path is: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-0.fc32.x86_64/jre/lib/amd64/server/libjvm.so.

Wouldn’t this path change when the openjdk package is updated? How can this be solved in a robust way that survives updates?