Skip to main content

Posts

Showing posts from March 31, 2013

An ingenious way to find Java on POSIX systems

This is Perl code. _java_bin returns the full path to the java executable.

From http://search.cpan.org/~dolmen/DateTime-TimeZone-HPUX-1.04/lib/DateTime/TimeZone/HPUX.pmour @JAVA_HOMES = ( '/opt/java1.4', ); { my $_java_bin; sub _java_bin { return $_java_bin if defined $_java_bin; $_java_bin = ''; # Default value: java not found (false) foreach ( (map { ("$_/jre/bin/java", "$_/bin/java") } (exists $ENV{JAVA_HOME} ? ($ENV{JAVA_HOME}) : ()), @JAVA_HOMES, ), (map { "$_/java" } split(/:/, $ENV{PATH}) ), ) { next unless -x "$_"; $_java_bin = $_; last; } return $_java_bin; } }