[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

New VM Selection Method

We need a standard, nice, easy to extend way for binary wrappers
in /usr/bin and/or startup scripts to locate their VM. There are a few
requirements that I had:

1) Whatever we do should be GUI configurable. I want to write a "System
VM Selection" control panel of some sort allowing the user to choose
which VM is used system-wide and also program specific.

2) It would be nice if a user (or us, as maintainers) could set the
system up so that a certain VM is used by default for a certain program.
There is a very obvious use case for wanting to run something like
Eclipse on Sun's VM, yet everything else on GCJ (at least until we are
feature complete with Sun!)

3) It should be overridable per user. If only one user wants to run
Eclipse on Sun, he should be able to.

So the obvious way to implement this is to write a shell script fragment
which queries a number of files and returns a valid path to a JAVA_HOME.
We then include this fragment at the top of existing wrappers, or such
as in the case of Ant, just replace the wrapper (the Ant wrapper sucks
really badly.)

Here's my idea. A JVM selection file is just a file listing JAVA_HOME
paths in order of preference. We put the default system one here:


Additionally, we create a directory to hold per program files.


A file in here would be for example named 'ant'. I'd like to talk about
this naming convention for these files. I'm thinking we'd use the same
stuff as like, /usr/share/$prog, not the specific package name.

The script would test for /etc/jvm.d/prog, test each JAVA_HOME listed
within, then, if it hasn't found a jvm yet, proceed with /etc/jvm.

We could also have it check ~/.jvm.d and ~/.jvm in the same manor.

Because I like doing things before I talk about them, I did this. This
file would be cleaned up, placed in java-common, perhaps
in /usr/share/java-common/jvm.sh, and jvm_find would be called in each


function jvm_scan_file() {

    while read jvm; do
        if [ -x "$jvm/bin/java" ]; then
            echo $jvm
    done < <(cat "$file" | grep -v '#')

function jvm_find() {

    if [ -r "$user_program_file" ]; then
        jvm="$(jvm_scan_file "$user_program_file")"

    if [ -r "$HOME/.jvm" ]; then
        jvm="$(jvm_scan_file "$HOME/.jvm")"

    if [ -r "$program_file" ]; then
        jvm="$(jvm_scan_file "$program_file")"

    if [ -z "$jvm" ]; then
        jvm="$(jvm_scan_file /etc/jvm)"

    echo "$jvm"

Then a wrapper just sources it, JAVA_HOME=`jvm_find myname`, and goes

Please discuss!

Jerry Haltom <wasabi@larvalstage.net>

Reply to: