use different java version to run two programs

There's no point in having them both in $PATH because only one will get used. You could symlink one to a different name -- e.g. java6 -- I've never tried this w/ java and not sure if it would work.

The best way to do this would be to install one of them (presumably 1.6) in a location like /opt/java6, leaving 1.7 as the default. Then when you want to use 6:

export PATH=/opt/java6/bin:$PATH

And start it from the command line. You could also put all that together in a script. Don't try to run Cassandra from the same shell after that unless you remove that from $PATH (easy way to check is echo $PATH).

To automate this for one specific application:

#!/bin/sh

export PATH=/opt/java6/bin:$PATH
exec /path/to/application

You can then put that somewhere in the regular $PATH (e.g., /usr/local/bin), make sure it is executable (chmod 755 whatever.sh) and start the application that way. It will then not affect $PATH in the process which launches it.

Tags:

Java

Centos

Jdk