Ruby learning journey (4): jruby's hello World

Source: Internet
Author: User

 

1. Determine the installation environment

Before installing jruby, determine the JDK version on the local machine. If you are using jruby 1.1.1, you can use JDK 1.4 (from the network, not personally proven). However, if you are using jruby 1.1.2, the JDK version is preferably 1.6. JDK may not be supported by some earlier versions. I have not proved the relationship between the specific versions one by one, because it is complicated and I have not found any documentation.

Ii. Get versions

Download of jruby: http://dist.codehaus.org/jruby/jruby-bin-1.1.2.zip

Java 1.6 download: http: // 192.18.108.239/ECOM/ecomticketservlet/Servlets/-2147483648/2617791231/1/877946/877778/2617791231/2ts +/westcoastfsend/jdk-6u5-oth-JPR/jdk-6u5-oth-JPR: 2/jdk-6u5-windows-i586-p.exe

Java 1.6 Chinese API: http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/chm/JDK_API_1_6_zh_CN.CHM

(This document seems to have been translated directly using the translation software)

Iii. installation and configuration:

The installation of jruby is quite simple. First, extract the downloaded compressed package to any directory, and then add jruby_home in the environment variable to point to your decompression directory. Add/jruby-1.1.2/bin in path,

JDK installation and configuration will not be mentioned, and a lot of online searches will be made.

4. Verify Installation

Enter the CMD command line and enter jruby-V. The output result is as follows:

Ruby 1.8.6 (Rev 6586) [x86-jruby1.1.2] 'cmd' is not an internal or external command or a runable program or batch file.

I have been very depressed. What was the last prompt ......

Input Hello World:

Add a helloworld. RB file in the root directory of the C drive. edit the file in notepad and enter the following content:

Puts "Hello World"

Save and exit. Then enter jruby helloworld. Rb in cmd and press Enter. At this time, the output result should be able to see helloworld, so that the installation is complete.

Then we try to use jruby to call the Java class and modify the helloworld. RB file. The modified content is as follows:

require 'java'include_class("java.lang.System")System.out.println("hello world")
Save the modification and exit. Go to the CMD command line and run the following command:
jruby HelloWorld.rb
The output result should be hello World, proving that jruby can call the Java class method. However, the problem is that you do not know how to call a custom Java class.

Remember, if you use jruby-1.1.2, be sure not to use JDK 1.4, if you are prompted to not find the main method when running the jruby program, or Org. ruby. most of these problems are caused by version inconsistencies. My personal suggestion is that if you use a jruby-1.1.2, you 'd better install JDK 1.6; if you're not using a jruby-1.1.2, you 'd better replace it with jruby-. 1.1.2.

Note: The error message for the last line in the output result of script running is as follows:

'Cmd' is not an internal or external command, or a program or batch file that can be run.

I accidentally found that the solution can be solved by entering the bin directory under the jruby directory, modifying the jruby. BAT file under the directory, and commenting out the last line of code. The modified code is as follows:

Rem endlocal & CMD/C Exit/B % E %

When running the command line in cmd or eclipse, you will find that the error message is missing. This method ends on, and no exception has been found :).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.