Friday September 07, 2007
JRuby on Rails, NetBeans 6 and GlassFish V2 - Simplified Steps
The NetBeans IDE has simplified the steps to deploy JRuby on Rails application on GlassFish. This blog explains the steps and is an update to screencast #web6.
Download"
button in the Ruby column.New Project...".
Take all the defaults as shown below:
Next" and enter the values as shown below:
Add rake targets to support app server
deployment (.war)". This downloads the
goldfish (nee rails integration) plugin and installs in your
application. Choose the database that you'd like to work with using the
combo box:
Finish" button. I'm choosing the default
database (MySQL) in this case.mysqld -nt
--user root' in MYSQL_HOME/bin directory on Windows or
'./bin/mysqld_safe' from MYSQL_HOME directory
on Unix flavors.mysqladmin -u root create RailsApplication9_developmentGenerate..."
and enter the values as shown below:
OK".Generate..."
and enter the values as shown:
OK".Database Configurations",
"migrate" and open "001_create_greetings.rb".
Change the "self.up" helper method such that it looks
like:def self.up
create_table :greetings do |t|
t.column :data, :string
end
endRun Rake Target',
'db', 'migrate'. This generates the
appropriate database tables and the following is shown in the output
window:(in C:/Users/Arun Gupta/Documents/NetBeansProjects/RailsApplication9)
== CreateGreetings: migrating
=================================================
-- create_table(:greetings)
-> 0.1010s
== CreateGreetings: migrated (0.1110s)
========================================C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql --user root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.45-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use RailsApplication9_development;
Database changed
mysql> insert into greetings values (1, "Hello from database!");
Query OK, 1 row affected (0.10 sec)
mysql> exit;
ByeConfiguration" and
open "database.yml". Change the database entry in
production environment to point to "RailsApplication9_development"
instead of "RailsApplication9_production".Controllers", open "say_controller.rb"
and change "hello" helper method such that it looks
like:def hello
@hello_string = Greeting.find(1).data;
endViews", "say", open "hello.rhtml"
and add the following fragment at the bottom of the page:<%= @hello_string %>Run
Rake Target', 'war', 'standalone', 'create'
as shown here:
(in C:/Users/Arun Gupta/Documents/NetBeansProjects/RailsApplication9)
Assembling web application
Adding Java library commons-pool-1.3
Adding Java library activation-1.1
Adding Java library jruby-complete-1.0
Adding Java library bcprov-jdk14-124
Adding Java library rails-integration-1.1.1
Adding web application
Adding Ruby gem rails version 1.2.3
Adding Ruby gem rake version 0.7.3
Adding Ruby gem activesupport version 1.4.2
Adding Ruby gem activerecord version 1.15.3
Adding Ruby gem actionpack version 1.13.3
Adding Ruby gem actionmailer version 1.3.3
Adding Ruby gem actionwebservice version 1.2.3
Adding Ruby gem ActiveRecord-JDBC version 0.5
Creating web archiveRailsApplication9.war" in the project
directory.lib\ant\bin\ant -f setup.xmlbin\asadmin start-domainRailsApplication9.war) in "domains/domain/autodeploy"
directory.The application is accessible at "http://localhost:8080/RailsApplication9/say/hello".
Here are the improvements from the last time:
database.yml"
using default values for that database.war:standalone:create"
rake target. This allows the database to be accessed using the Ruby adapter
instead of the JDBC adapter and also uses the original format of "database.yml".Technorati: jruby ruby rubyonrails glassfish netbeans jrubyonglassfish mysql
Posted by Arun Gupta in web2.0 | Comments[22]
|
|
|
|
Today's Page Hits: 4654
Posted by Arun Gupta's Blog on September 07, 2007 at 05:40 AM PDT #
when I'm trying to create the war file ('Run Rake Target', 'war', 'standalone', 'create'), Rake is crashing with a timeout.
Posted by JS on September 07, 2007 at 10:21 AM PDT #
Arun, what makes this app a *JRuby* on Rails application instead of a *Ruby* on Rails application--how do you specify it within the IDE? Also, once you choose, can you switch back and forth between JRuby / Ruby (perhaps to test performance, etc.)? For the latter question, I don't think you can, because the code scripting is different, correct? Thanks, Glen
Posted by Glen on September 07, 2007 at 10:43 AM PDT #
Posted by Arun Gupta's Blog on September 07, 2007 at 02:43 PM PDT #
I am trying to run through this howto on my Ubuntu system, but the migrate step (5.1.2) bombs. Here is the trace:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
can't convert nil into String
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/vendor/mysql.rb:111:in `real_connect'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:389:in `connect'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:152:in `initialize'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `new'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `mysql_connection'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `send'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `connection='
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/query_cache.rb:54:in `connection='
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in `retrieve_connection'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:284:in `migrate'
/home/keith/netbeans-6.0-200709101200/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:4
Posted by Keith on September 10, 2007 at 09:23 PM PDT #
Keith, It seems like this is an issue with ActiveRecord-JDBC. I filed an issue at: http://jira.codehaus.org/browse/JRUBY-1341.
Posted by Arun Gupta on September 11, 2007 at 11:10 AM PDT #
Ruby is new for me.
Posted by heart5 on September 12, 2007 at 01:32 AM PDT #
The best place to get started with Ruby is http://www.ruby-lang.org/en/documentation/. Or if you want to learn JRuby then you can start at: http://jruby.codehaus.org/.
Posted by Arun Gupta on September 12, 2007 at 06:27 AM PDT #
Posted by Arun Gupta's Blog on September 12, 2007 at 06:51 AM PDT #
Posted by Arun Gupta's Blog on September 13, 2007 at 08:55 PM PDT #
Posted by Arun Gupta's Blog on September 13, 2007 at 08:55 PM PDT #
Posted by Arun Gupta's Blog on September 13, 2007 at 08:56 PM PDT #
Posted by Arun Gupta's Blog on September 14, 2007 at 06:13 AM PDT #
Thanks for the instructions. This mostly worked for me on MacOSX with a couple of modifications.
1) I also received Keith's error when running migrations. Adding "host: localhost" to each of the database.yml connection settings (development, test, and production) worked around that. Never had to set that before however. I'd be curious to know the best way to use the JDBC connector as an alternate.
2) The MacOS build for NetBeans includes a separate installer for Glassfish which installed glassfish at /Applications/NetBeans/glassfish-v2b58g/ so I was able to skip running "ant -f setup.xml". Also, "domains/domain/autodeploy" was "domains/domain1/autodeploy" for my installation.
Posted by victor cosby on September 25, 2007 at 10:05 PM PDT #
Thanks for this. It is very clear. It worked - eventually. The issues (which others might be interested in) for me were two. (i) In database.yml change socket: /var/lib/mysql/mysql.sock to host: localhost (as noted above). (ii) I am behind a firewall and cut off from web based resources. I needed to download and copy the following into JRUBY_HOME/lib - commons-pool-1.3.jar, activation-1.1.jar, jruby-complete-1.0.jar, bcprov-jdk14-124.jar, rails-integration-1.1.1.jar
Posted by Richard Forster on October 29, 2007 at 10:37 PM PDT #
The deployed application does not seem to handle 'redirect_to' instructions properly. For instance you could expand 'hello' to the following
def hello
@hello_string = Greeting.find(1).data;
if request.post?
redirect_to(:action => 'tom')
end
end
If there is an appropriate view for 'tom' this will work fine in webrick. If the application is deployed (as described above) to Glassfish
The initial invocation of say/hello is ok
but the attempted redirection does not generate a complete URL:
(localhost:8080/admin/tom)
I have tried fiddling with the routes.rb but with no success. link_to seems to be ok.
Posted by Richard Forster on November 11, 2007 at 06:27 PM PST #
thanks all.
Posted by evden eve nakliyat on November 25, 2007 at 10:00 AM PST #
Nice tutorial Arun. I had been struggling to get my database access to work until reading your blog. The key step for me was 5.4 - I didn't think to update the production database information in database.yml. Thanks, Brian.
Posted by Brian Leonard on November 26, 2007 at 05:25 PM PST #
Cool, glad you found it useful.
Posted by Arun Gupta on November 26, 2007 at 07:00 PM PST #
rake war:standalone:create
gives
(in c:/ruby/app)
info: Assembling web application
info: Packing needed java lib....
info: Packing needed Ruby gems...
info: Packing needed files...
info: Creating web archive
reak aborted!
Error: failed to create archive,error code
i'm trying to deploy my rails application into tomcat, installed goldspike but rake is not working
(using ruby not jruby)
Posted by disha on December 14, 2007 at 02:21 AM PST #
If you are using NetBeans 6, then this is a known issue as described at:
http://www.netbeans.org/issues/show_bug.cgi?id=123900
I plan to try this outside NetBeans and report back.
Posted by Arun Gupta on December 14, 2007 at 07:15 AM PST #
Not using any type of editors or IDE's
Posted by disha on December 15, 2007 at 04:19 AM PST #