Đang chuẩn bị liên kết để tải về tài liệu:
Beginning Java SE 6 Platform From Novice to Professional phần 8

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

IllegalArgumentException được ném nếu danh sách các định dạng không được biết đến. Trả về thời gian sống giá trị cho các bó tài nguyên được tải thông qua ResourceBundle.Control này. NullPointerException là ném ra nếu basename hay địa điểm là null. Xác định các gói lưu trữ đã hết hạn cần phải được | 334 CHAPTER 9 SCRIPTING Listing 9-15. TempConverter.rb TempConverter.rb class TempConverter def c2f degrees degrees 9.0 5.0 32 end def f2c degrees degrees-32 5.0 9.0 end end def getTempConverter TempConverter.new end The application uses ScriptEngineManager s getEngineByName method and the jruby short name to access JRuby s script engine. It loads and evaluates TempConverter.rb invokes getTempConverter to obtain a TempConverter instance and uses this instance to invoke TempConverter s methods. The application is presented in Listing 9-16. Listing 9-16. WorkingWithJRuby.java WorkingWithJRuby.java import java.io. import javax.script. public class WorkingWithJRuby public static void main String args throws Exception ScriptEngineManager manager new ScriptEngineManager The JRuby script engine is accessed via the jruby short name. ScriptEngine engine manager.getEngineByName jruby Evaluate TempConverter.rb to generate intermediate code. CHAPTER 9 SCRIPTING 335 engine.eval new BufferedReader new FileReader TempConverter.rb Invocable invocable Invocable engine Object tempconverter invocable.invokeFunction getTempConverter double degreesCelsius degreesCelsius Double invocable.invokeMethod tempconverter f2c 98.6 System.out.println 98.6 degrees Fahrenheit degreesCelsius degrees Celsius double degreesFahrenheit degreesFahrenheit Double invocable.invokeMethod tempconverter c2f 100.0 System.out.println 100.0 degrees Celsius degreesFahrenheit degrees Fahrenheit To run this application you will need to add jruby-engine.jar and jruby.jar located in the JRuby home directory s lib subdirectory to the classpath via either the classpath environment variable or the java tool s -cp option . Here s an example for the Windows platform java -cp c jruby-1.0 lib jruby.jar c jruby-1.0 lib jruby-engine.jar . WorkingWithJRuby You should observe the following output 98.6 degrees Fahrenheit 37.0 degrees Celsius 100.0 degrees Celsius 212.0 degrees Fahrenheit If you want to play with JRuby via .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.