As a Java programmer, you don't want to use Ruby in your product until you can interact with existing Java applications and class libraries, which support many of the basic features of Ruby. An open source Ruby interpreter under JRUBY,JVM can use Ruby class libraries in Java. Like a standard ruby interpreter, Ruby code can be executed correctly in JRuby, except for invoking native methods (c code) or Java class libraries using Ruby.
Compared to Microsoft's. NET platform, the JVM is often able to support only one language. But in fact, the JVM platform is not only capable of supporting Java, but it can support Python, JavaScript, Groovy, Scheme, and many other languages, which means that Ruby code can interact well with these languages when necessary.
In mid-July 2006, JRuby only had a preview version (0.9). But it has developed rapidly: A team of volunteers has released five editions since January 2005. JRuby is maturing through ongoing evaluation tests for the standard interpreter, and now more than 90% of the tests are in the framework of basic support for Ruby on Rails.
To try JRuby, make sure that the Java SE 5 is installed and that the JAVA_HOME environment variable is set up as well. Download the compressed package from the JRuby Engineering page and unzip it. Sets the Jruby_home environment variable to the root directory of the JRuby installation. You can try to interact with JIRB in the bin directory. On most occasions, you will use the JRuby interpreter-Create a file to pass the filename as a parameter to the JRuby Bin directory under the batch script.
In addition to executing the previous Ruby code, you can still use JRuby to construct Java objects, invoke Java methods, and inherit from a Java class. A Ruby class can implement a Java interface--you can invoke the Ruby method statically in Java if necessary.
To initialize a class library in order to access Java from Ruby, you need to start with the "Java" command. Next, use the Include_class method to specify the Java class you want to use, for example, Include_class "Javax.jms.Session". You can use Include_package to import the entire Java package into the Ruby module. As with wildcard statements for Java import packages, it is wise to avoid include_package using the resulting name conflicts, and in JRuby, it is particularly unwise for the interpreter to search all packages for the class that is needed. Use Include_class as strictly as you can.
Many Java standard classes have the same names as Ruby classes. To resolve such conflicts, pass a code block to the Include_class function, return a new name for the Java class, and JRuby will use that name as the alias for the Java class.