JRuby on Rails, NetBeans 6 and GlassFish V2 - Simplified Steps
Posted by arungupta on September 7, 2007 at 5:35 AM PDT
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 the install the latest
NetBeans 6
Nightly. I downloaded the Ruby pack by clicking on the "Download"
button in the Ruby column. - Create a new Rails Application
- Right-click in the Project window and select "
New Project...".
Take all the defaults as shown below:

- Click on "
Next" and enter the values as shown below:

Notice, we have selected "
". This downloads theAdd rake targets to support app server
deployment (.war)
goldfish (nee rails integration) plugin and installs in your
application. Choose the database that you'd like to work with using the
combo box:

and then click on "Finish" button. I'm choosing the default
database (MySQL) in this case.
- Right-click in the Project window and select "
- Create Database
- Download and install
MySQL Community
Server 5.0 (lets say MYSQL_HOME). - Start MySQL database server by giving the command '
' inmysqld -nt
--user rootMYSQL_HOME/bindirectory on Windows or
'./bin/mysqld_safe' fromMYSQL_HOMEdirectory
on Unix flavors. - Create a database by giving the following commands:
mysqladmin -u root create RailsApplication9_development
- Download and install
- Create Generators
- Generate a model - Right-select the project, select "
Generate..."
and enter the values as shown below:

and click on "OK". - Generate a controller - Right-select the project, select "
Generate..."
and enter the values as shown:

and click on "OK".
- Generate a model - Right-select the project, select "
- Configure Model and Controller
- Configure Model
- In the NetBeans IDE, expand "
Database Configurations",
"migrate" and open "001_create_greetings.rb".
Change the "self.up" helper method such that it looks
like:
def self.up<br>
create_table :greetings do |t|<br>
t.column :data, :string<br>
end<br>
end - Right-select the project, select '
Run 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)<br>
== CreateGreetings: migrating
=================================================<br>
-- create_table(:greetings)<br>
-> 0.1010s<br>
== CreateGreetings: migrated (0.1110s)
======================================== - Add data to the database tables using the following commands in
a shell window:
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql --user root<br>
Welcome to the MySQL monitor. Commands end with ; or \g.<br>
Your MySQL connection id is 5<br>
Server version: 5.0.45-community-nt MySQL Community Edition (GPL)<br>
<br>
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br>
<br>
mysql> <b>use RailsApplication9_development;</b><br>
Database changed<br>
mysql> <b>insert into greetings values (1, "Hello from database!");</b><br>
Query OK, 1 row affected (0.10 sec)<br>
<br>
mysql> <b>exit;</b><br>
Bye
- In the NetBeans IDE, expand "
Configuration" and
open "database.yml". Change the database entry in
production environment to point to "RailsApplication9_development"
instead of "RailsApplication9_production".
- In the NetBeans IDE, expand "
- Configure Controller
- Expand "
Controllers", open "say_controller.rb"
and change "hello" helper method such that it looks
like:
def hello<br>
@hello_string = Greeting.find(1).data;<br>
end - Expand "
Views", "say", open "hello.rhtml"
and add the following fragment at the bottom of the page:
<%= @hello_string %>
- Expand "
- Configure Model
- Create a WAR file
- In the NetBeans IDE, right-select the project, select '
', 'Run
Rake Targetwar', 'standalone', 'create'
as shown here:

and the following is shown in the output window:
(in C:/Users/Arun Gupta/Documents/NetBeansProjects/RailsApplication9)<br>
Assembling web application<br>
Adding Java library commons-pool-1.3<br>
Adding Java library activation-1.1<br>
Adding Java library jruby-complete-1.0<br>
Adding Java library bcprov-jdk14-124<br>
Adding Java library rails-integration-1.1.1<br>
Adding web application<br>
Adding Ruby gem rails version 1.2.3<br>
Adding Ruby gem rake version 0.7.3<br>
Adding Ruby gem activesupport version 1.4.2<br>
Adding Ruby gem activerecord version 1.15.3<br>
Adding Ruby gem actionpack version 1.13.3<br>
Adding Ruby gem actionmailer version 1.3.3<br>
Adding Ruby gem actionwebservice version 1.2.3<br>
Adding Ruby gem ActiveRecord-JDBC version 0.5<br>
Creating web archive - This creates "
RailsApplication9.war" in the project
directory.
- In the NetBeans IDE, right-select the project, select '
- Download, Install and Start GlassFish.
- Download GlassFish
recent
build. - Install by giving the command:
java -jar filename.jar
This creates "glassfish" directory in your current directory. - In GlassFish install directory, set up the server by giving the
following command:
lib\ant\bin\ant -f setup.xml - Start the server by giving the following command
bin\asadmin start-domain
- Download GlassFish
- Copy the WAR file (
RailsApplication9.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:
- During the project creation, there was an option to select the database
to be used by the application. This creates the "database.yml"
using default values for that database. - During the project creation, there was an option to add add rake targets
for the WAR creation. This made the steps to explicitly install the
repository and install the plugin redundant. - ActiveRecord-JDBC 0.5 provides a
simplified database configuration and is used by the "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
Related Topics >>
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 2511 reads





