jruby – Get Version Information

Background

As part of a troubleshooting session that I will be undertaken I wanted to start getting familiar with what jruby has in terms of API for discovering the Java Version that it is running under.

Code

Ruby

Version.rb


require 'date'

require 'java'

require 'rbconfig'
include RbConfig

require 'io/console'

java_import java.lang.System

class Version

    # ruby class variables are prefixed with '@@' .
    @@javaRTVersion = "";
    @@rubyPlatform = "";
    @@hostOS = "";
    @@acquired = false;

    #Constructor
    def initialize()

    end

    def self.acquire

        @@javaRTVersion = System.getProperties["java.runtime.version"]

        @@rubyPlatform = RUBY_PLATFORM

        @@hostOS = CONFIG['host_os']

    end 

    # hostOS
    def self.hostOS

        if (@@acquired == false)

            self.acquire()

            @@acquired = true

        end

        return @@hostOS

    end 

    # java runtime version
    def self.javaRTVersion

        if (@@acquired == false)

            self.acquire()

            @@acquired = true

        end

        return @@javaRTVersion

    end     

    # the getter is defined to return the class variable when called
    def self.rubyPlatform

        if (@@acquired == false)

            self.acquire()

            @@acquired = true

        end

        return @@rubyPlatform

    end 

end

def waitForKeyPress

    puts
    puts

    puts "Press enter to continue"

    STDIN.getch()

end 

objV = Version.new()

# Access it's attributes.
puts
puts "hostOS is " + Version.hostOS
puts "javaRTVersion is " + Version.javaRTVersion
puts "rubyPlatform is " + Version.rubyPlatform

waitForKeyPress()

Command File

Objective

Ran again JDK 1.8, 1.9 ( v9 ) and 1.10 ( v10 ).

initiate.cmd


setlocal

REM SET JAVA_HOME to Version 1.8
rem set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181"
rem set "JAVA_HOME=C:\Program Files\Java\jdk-9.0.4"
set "JAVA_HOME=C:\Program Files\Java\jdk-10.0.2"

set "JRUBY_BIN=C:\Downloads\jruby\v9.2\zip\jruby-dist-9.2.0.0-bin\jruby-9.2.0.0\bin"

set "_app=Version.rb"

%JRUBY_BIN%\jruby.bat "%_app%"

endlocal

Output

JDK 1.8

javaVersion_run_1DOT8_20180816_0435AM

JDK 1.9

Image

javaVersion_run_1DOT9_20180816_0439AM

Textual


WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jruby.runtime.encoding.EncodingService to field java.io.Console.cs
WARNING: Please consider reporting this to the maintainers of org.jruby.runtime.encoding.EncodingService
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

hostOS is mswin32
javaRTVersion is 9.0.4+11
rubyPlatform is java

JDK 1.10

Image

javaVersion_run_1DOT10_20180816_0445AM

Textual


WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jruby.runtime.encoding.EncodingService to field java.io.Console.cs
WARNING: Please consider reporting this to the maintainers of org.jruby.runtime.encoding.EncodingService
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

hostOS is mswin32
javaRTVersion is 10.0.2+13<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;">&#65279;</span>
rubyPlatform is java

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s