1. prerequesite assume that you have installed jruby and JDK 1.7 is preferred. 2. Install rails to install rails4.0.0:
C:\>jruby -S gem install rails -V
View the installed rails version:
C:\>jruby -S rails -vRails 4.0.0
3. Create a new rails apps
C:\>jruby -S rails new demo
In addition, the bundle install is canceled because the master branch version of activerecord-jdbc-adapter installed by default is used. Currently, rake dB is executed: the wrong number of arguments calling exec_insert (5 for 3) error occurs in the migrate command. Therefore, modify gemfile to use its 1.3.0.beta2 version. (This step is an appropriate method, you don't have to worry about it in the future): If you are using the SQLite database, you will:
gem 'activerecord-jdbcsqlite3-adapter'
Changed:
gem 'activerecord-jdbcsqlite3-adapter', '1.3.0.beta2'
If the MySQL database is used:
gem 'activerecord-jdbcmysql-adapter'
Changed:
gem 'activerecord-jdbcmysql-adapter','1.3.0.beta2'
Then proceedJruby-s bundle installInstall gem. If you use the SQLite database, you can configure it by default. If you use the MySQL database, modify the database. yml uses the development environment as an example. Here, the username, password, host, and port are configured according to the actual situation:
development: adapter: mysql encoding: utf8 reconnect: false database: demo_development username: user password: user_password host: localhost port: 3306
Finally, start the rails app:
C:\DEMO>jruby -S rails s
However, an error occurs again:
OpenSSL::Cipher::CipherError: Illegal key size: possibly you need to install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for your JRE
Install JCE and download an unlimitedjcepolicyjdk7.zip file from the Oracle official website. After decompression, the unlimitedjcepolicyjdk7.zip file contains two jar files: local_policy.jar and us_export_policy.jar. Replace these two files with two files of the same name under the $ java_home/JRE/lib/security directory. For example, on my computer, replace c: \ Program.
Files \ Java \ jdk1.7.0 _ 25 \ JRE \ Lib \ Security directory. After replacement, restart the computer. In this case, you can run the jruby-s rails s app correctly. 4. Configure the Java class path. If you need to use the Java external class in rails, You need to configure$ ClasspathFirst, let us put all the required Java classes in the rails_root/lib/Java folder. In the environment. RB fileRequire file. expand_path ('../application', _ file __)Then add the Code:
require 'java'$CLASSPATH << File.join(Rails.root, 'lib','java')
In this way, if there is a compiled Java class under this directoryExample. myclassThis class can be used in rails like this:
mc=Java::example.MyClass.new
If an external jar is used, you must add the code that references the jar, and add the following in the environment. RB file:
Dir.glob(File.join(Rails.root, 'lib','java',"**","*.jar")).each do |jar| $CLASSPATH << jarend
So the final environment. RB file looks like this: