I am learning Jruby these days and faced few issues in creating my first application in jruby. I followed same steps which i have used for the creation of Ruby app. I jruby does go through smoothly. I think this blog will help people who are getting same problem.
go to working directory as I have TEST as working directory and then type Jruby command to create the new application MYAPP
E:\TEST\>jruby -S rails new MyApp -d mysql
one execution of the command is done a new application folder MYAPP will be created which will support mysql database. Now type command
E:\TEST\> cd MyApp
Once it is done now go to database.yml file and enter the password of your MySql Database. Save it. After this exexute command “Bundle Install”
You will see that it is throwing an error for Mysql2 specifically for the JRuby. Now to make it work we need a work around. So workaround is we need to download the specific gen which we need for our application, for my application i downloaded the gem “mysql2-0.2.6-x86-mingw32.gem ” after that go to command prompt and install this gem manually
E:\TEST\MyApp\>jruby -S gem install E:\Installation\mysql2-0.2.6-x86-mingw32 –include-dependencies
Then go to GemFile and make following entries for the MySql2
First remove the gem ‘mysql2’ statement or just put Hash (#) infront of the statement, as for the JRuby we are manually installing th mysql gem. Then add the following statements to the GemFile:
- gem ‘activerecord-jdbc-adapter’
- gem ‘activerecord-jdbcmysql-adapter’
- gem ‘jdbc-mysql’
Once GemFile saved go to command prompt and execute “bundle Install” command
E:\TEST\MyApp\>Jruby – S bundle install
it is will be executed successfully and when you run the command “gem list” you will see the mysql in the installed gems. then run the command to create the database.
E:\TEST\MyApp\>jruby -S rake db:create
if it gives you error on db:create then open the Database.yml file and change the shown section, then again execute the rake db:create statement.
once all this is done run the server and you are all set to run the application.
E:\TEST\MyApp\>jruby -S rails server