Created
January 11, 2012 21:57
-
-
Save tychobrailleur/1597006 to your computer and use it in GitHub Desktop.
Set current jvm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env jruby | |
require 'java' | |
JVMS = ["/home/sebastien/dev/jdk1.6.0_25", | |
"/home/sebastien/dev/jdk1.6.0_30", | |
"/home/sebastien/dev/jdk1.7.0_02"] | |
current_java_home = ENV['JAVA_HOME'] | |
if ARGV.size != 1 | |
puts "Usage: select_jvm.rb <number>" | |
exit | |
end | |
arg = ARGV[0] | |
if arg == "--help" || arg == "-h" | |
puts "Usage: select_jvm.rb <number>" | |
puts "List of JVMs:" | |
JVMS.each_with_index do |jvm, index| | |
puts "#{index+1}) #{jvm}" | |
end | |
else | |
selection = ARGV[0].to_i-1 | |
selected_jvm = JVMS[selection] | |
if selected_jvm != current_java_home | |
current_path = ENV['PATH'] | |
ENV['PATH'] = current_path.gsub(File.join(current_java_home, 'bin'), File.join(selected_jvm, 'bin')) | |
ENV['JAVA_HOME'] = selected_jvm | |
end | |
end | |
`java -version` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment