I poked around with strace a bit more. MatlabEngine.startMatlab attempts to load libnativemvm. If LD_LIBRARY_PATH contains /usr/local/MATLAB/[version]/bin/glnxa64/, this succeeds. If LD_LIBRARY_PATH is empty, the System.loadLibrary("libnativemvm") call fails:
java.lang.UnsatisfiedLinkError: no nativemvm in java.library.path
It is quite easy to add /usr/local/MATLAB/[version]/bin/glnxa64/ to java.library.path, but this only works for libnativemvm.so; any libraries it references can't be found. Examining the output of strace, we see that jvm looks for:
28814 16:36:43 stat("/usr/lib/jvm/java-8-oracle/jre/lib/amd64/libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
28814 16:36:43 stat("./libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
28814 16:36:43 stat("/usr/java/packages/lib/amd64/libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
28814 16:36:43 stat("/usr/lib64/libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
28814 16:36:43 stat("/lib64/libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
28814 16:36:43 stat("/lib/libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
28814 16:36:43 stat("/usr/lib/libnativemvm.so", 0x7ff2dadaf340) = -1 ENOENT (No such file or directory)
So a simple solution is:
ln -s /usr/local/MATLAB/R2020a/bin/glnxa64/libnativemvm.so libnativemvm.so
Now we find:
java.lang.UnsatisfiedLinkError: no nativecapabilities in java.library.path
Adding:
ln -s /usr/local/MATLAB/R2020a/bin/glnxa64/libnativecapabilities.so libnativecapabilities.so
allows the call to startMatlab to complete. Of course, this isn't a really portable solution.
What would be nice would be if startMatlab looked in ./javalibrarypath.txt or ~/.matlab/[version]/javaclasspath.txt, but it doesn't. As best I can tell, it doesn't touch any file that has .txt or .sh.
Why not just define LD_LIBRARY_PATH in .bashrc? Because too many other things hate the Matlab libraries:
export LD_LIBRARY_PATH=/usr/local/MATLAB/R2020a/bin/glnxa64
$ curl localhost:9000
curl: /usr/local/MATLAB/R2020a/bin/glnxa64/libcurl.so.4: no version information available (required by curl)
curl: (48) An unknown option was passed in to libcurl
Suggestions?