How can I make lazy/delay loading work in Linux?

心不动则不痛 提交于 2019-12-06 15:55:01

How did you conduct the smart search on windows? There are a couple of "normal" places to look in Linux.

A lot of times the $JAVA_HOME environment variable is set to the current JRE.

I don't have ready access to all of the systems you listed, but on some distros, you have a symlink /usr/java/latest which will point to the latest installed version.

In general, if there's a JRE installed, it will probably be in one of /usr/lib/jvm*, /usr/java*, /usr/lib/java*, or possibly one of the lib64 varieties of the above.

Of course, the above methods will most likely point you to a JRE. Deciding which to use might be tricky, but if your code doesn't rely on the latest and greatest, it will probably be okay.

I suppose as part of asking your user to install a JRE if one can't be found, you could ask them to set $JAVA_HOME as that's fairly standard practice.

I don't know of a sure fire way for it to work on all distros, since part of the problem stems from the nature of *nix distributions. There may be an additional convention that I'm missing, however.

If your program simply runs java /path/to/foo.jar then the solution is easy on Debian-derived systems:

$ ls -l /usr/bin/java /etc/alternatives/java /usr/lib/jvm/java-6-sun/jre/bin/java | awk '{print $1, $8, $9, $10}'
lrwxrwxrwx /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
lrwxrwxrwx /usr/bin/java -> /etc/alternatives/java
-rwxr-xr-x /usr/lib/jvm/java-6-sun/jre/bin/java  
$ 

The java in /usr/bin/java is a symlink to a symlink to the real JRE.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!