find-default-jvm 1 user commands nosh
find-default-jvm set the JAVA_HOME environment variable to denote the default JVM
`find-default-jvm` next-prog

## Description

`find-default-jvm` is a chain-loading utility that sets the `JAVA_HOME` environment variable to denote the root directory for the default JVM, and then chain loads to next-prog with the execvp 3 function. If the environment variable is already set, it simply chain loads and does not alter it.

next-prog may contain its own command line options, which `find-default-jvm` will ignore.

First the files `/usr/local/etc/javavms`, `/etc/javavms`, and `/usr/pkg/etc/javavms` are checked for in order. If such a file exists, it is expected to be a (potentially commented) list of JVM programs, in descending priority order. The default JVM is the first in the list. The `JAVA_HOME` variable is set to the root of the JVM subtree, which is presumed to be the directory above the directory containing the named JVM program.

If none of those files exist, then if the `/usr/lib/jvm` directory exists it is presumed to contain all of the JVM subtree root directories, either directly or as symbolic links. The `JAVA_HOME` variable is set to the one named `default-java` if that exists, or failing that the one named `default-runtime` if that exists.

Failing either of those, the `/usr/local/bin/java`, `/usr/pkg/bin/java`, `/usr/bin/java`, and `/bin/java` files are checked in order, and if found the `JAVA_HOME` variable is set to the root of the JVM subtree, which is presumed from those filenames as aforementioned.

Finally, as a last resort, the JVM root is presumed to be `/` which implies the JVM program at `/bin/java`.

## See also

find-matching-jvm 1

  This addresses the more common use case of wanting to find JVMs that support particular versions of Java; but can potentially fail if there are no JVMs on the system even if the matching criteria are entirely open.

## Author

Jonathan de Boyne Pollard