Wednesday October 31, 2007
TOTD #15: Delete/Update Row from Database using jMaki Data Table
A Previous Entry explained how a Data Table widget can be populated from a database using Java Persistence API (JPA). This TOTD extends that entry and explains how a selected row from the Data Table can be deleted from the database. This entry is created based upon a requirement from Dave Briccetti at Silicon Valley Code Camp 2007 last weekend.
The first part of the entry is also a re-write of using NetBeans 6 and the latest jMaki NetBeans plugin.
Web Application'
project and name it as 'jmaki-database'.
Next' button, add 'jMaki Ajax Framework'
and choose 'Standard' layout as shown below:
Finish' button.Runtime' tab, expand Databases, connect
to the default database (with the URL 'jdbc:derby://localhost:1527/sample
[app on APP]'). Specify the username 'app' and password
'app'.Execute Command...'
and issue the command:create table BOOKS (title varchar(255),
author varchar(255),
isbn varchar(255),
description varchar(255),
PRIMARY KEY (isbn))INSERT INTO BOOKS VALUES('Galloway Book of Running', 'Jeff Galloway',
'ABC001', 'The best book on running');
INSERT INTO BOOKS VALUES('The Complete Book of Running', 'James Fixx',
'ABC002', 'Oldest book of running');
INSERT INTO BOOKS VALUES('The Runners Handbook', 'Bob Glover', 'ABC003',
'Bestselling Guide for Beginning and Intermediate Runners');
INSERT INTO BOOKS VALUES('Daniel Running Formula', 'Jack Tupper Daniels',
'ABC004', 'Proven programs 800m to Marathon');
INSERT INTO BOOKS VALUES('Chi Running', 'Danny Drever', 'ABC005',
'Revolutionary approach to effortless, injury-free running');
INSERT INTO BOOKS VALUES('Running for Mortals', 'John Bingham', 'ABC006', 'A
common sense plan for changing your life through running');
INSERT INTO BOOKS VALUES('Marathoning for Mortals', 'John Bingham',
'ABC007', 'Regular person guide to marathon');
INSERT INTO BOOKS VALUES('Marathon', 'Hal Higdon', 'ABC008', 'The Ultimate
Training Guide');jmaki-database',
right-click and select 'New' and choose 'Entity
Classes From Database...'.jdbc/sample' as 'Data Source'.BOOKS' in 'Available Tables' and
click on 'Add' and enter the values as shown below:
Next'.server' as shown below:
Create Persistence Unit...' to create the
persistence unit and enter the values as shown below:
Create'.and click on 'Finish'.
@NamedQuery(name = "Books.findAll", query = "SELECT b FROM Books b")Configuration Files' and open
'persistence.xml'.Add Class' button and choose 'server.Books'
class and click 'OK'. This will ensure that the generated
entity class is explicitly recognized by the EntityManagerFactory.Web Pages', select 'New'
and then 'JSP...'. Give the name as 'data' as
shown:
Finish'.data.jsp' with the
following:<%@ page import="java.util.*" %>
<%@ page import="server.Books" %>
<%@ page import="javax.persistence.*" %>
<%
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("jmaki-databasePU");
EntityManager em = emf.createEntityManager();
List<Books> list = em.createNamedQuery("Books.findAll").getResultList();
out.println("{columns : [" +
"{ label : 'Title', id : 'title'}," +
"{ label :'Author', id : 'author'}," +
"{ label :'ISBN', id : 'isbn'}," +
"{ label :'Description', id : 'description'}" +
"],");
out.println("rows: [");
for (int i=0; i<list.size(); i++) {
Books b = list.get(i);
out.print("{ id: '" + b.getIsbn() + "', " +
"title: '" + b.getTitle() + "'," +
"author: '" + b.getAuthor() + "'," +
"isbn: '" + b.getIsbn() + "'," +
"description: '" + b.getDescription()
+ "'}");
if (i < list.size()-1)
out.println(",");
else
out.println();
}
out.println("] }");
%>index.jsp', drag-and-drop a 'Yahoo Data Table' widget from the jMaki Palette in the 'Main
Content Area'.<a:widget name="yahoo.dataTable"
value="{columns :
[
{ label : 'Title', id : 'title'},
{ label :'Author', id : 'author'},
{ label : 'ISBN', id : 'isbn'},
{ label : 'Description', id : 'description'}
],
rows :
[
{ title : 'Book Title 1', author : 'Author 1', isbn: '4412', description
: 'A Some long description'},
{ id : 'bar', title : 'Book Title 2', author : 'Author 2', isbn :
'4412', description : 'A Some long description'}
]
}" />
<a:widget name="yahoo.dataTable" service="data.jsp" />
The 'service' attribute tells jMaki runtime to retrieve the data
for DataTable widget from 'data.jsp' instead of the using static
data.
Source Packages', 'server',
edit 'Books.java' and add the following NamedQuery:@NamedQuery(name = "Books.deleteByIsbn", query = "DELETE FROM Books b
WHERE b.isbn = :isbn")Web Pages', select 'New'
and then 'JSP...'. Give the name as shown:
Finish'.delete.jsp' with the
following:<%@ page import="javax.persistence.*" %>
<%
String isbn = request.getParameter("isbn");
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("jmaki-databasePU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.createNamedQuery("Books.deleteByIsbn").
setParameter("isbn", isbn).
executeUpdate();
em.getTransaction().commit();
%>Web pages' and edit 'glue.js' to add
the following fragment in '*onSelect' subscribe method:jmaki.doAjax({method: "POST",
url: "delete.jsp?isbn=" + encodeURIComponent(args.value.isbn),
callback: function(_req) {
jmaki.publish('/jmaki/table/removeRow', { targetId:
args.value.isbn });
}
});index.jsp' as:<a:widget name="yahoo.dataTable" service="data.jsp" subscribe="/jmaki/table"/>That's it! Now clicking on any row of the table will delete that particular row from the database and also from the table. If jMaki Debugger Console is enabled, then the messages are shown as below:

Using the similar steps described in bullet #9-13, a row can be updated in the database.
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totd jmaki glassfish netbeans jpa database
Posted by Arun Gupta in web2.0 | Comments[44]
|
|
|
|
|
Tuesday October 30, 2007
Silicon Valley Code Camp Trip Report
Rama and I presented on Metro and jMaki in Silicon Valley Code Camp last Saturday. Here are the pictures
It was good to meet Peter Kellner (SVCC Orgaznier, Aaron Houston (Program Coordinator for JUGs), Van Riper (Silicon Valley JUG Founder), Kevin Nelson (Silicon Valley Web JUG Founder), Juval Lowy (of iDesign) and many others.
And here is a recap of the question/answers asked during the two sessions:
There are changed signatures when using JAX-WS
2.1.3 with JDK 6. How does it work ?
JDK 6 U3 contains JAX-WS 2.0 APIs. JAX-WS 2.1.x contains JAX-WS 2.1
APIs. In order to override the default APIs, the endorsed directory
mechanism needs as explained
here.
Next stop, GlassFish Day @ Beijing.
Technorati: conf siliconvalleycodecamp metro webservices interoperability jmaki web2.0 glassfish netbeans
Posted by Arun Gupta in webservices | Comments[2]
|
|
|
|
|
Monday October 29, 2007
What are the dates ? Nov 1 - 2, 2007 for Sun Tech Days and Nov 3, 2007 for GlassFish Day
Where is the venue ? Beijing International Conference Center. More details here.
What is the agenda ? Sun Tech Days agenda here, GlassFish Day agenda here. You experience multiple tracks dedicated to Java and Solaris, Hands-on-labs, Community events such as GlassFish Day. And above all you get 1-1 interaction with industry experts.
What do you get ? Complete immersion in GlassFish and it's ecosystem.
How to register ? Click here.
See you there!
Technorati: conf suntechdays glassfish
Posted by Arun Gupta in webservices | Comments[4]
|
|
|
|
|
Tuesday October 23, 2007
Metro & jMaki @ Silicon Valley Code Camp - FREE event on Oct 27 & 28
|
|
Metro (Takes 2 to Tango: Java Web services and .NET interoperability) | Room 4306 | Saturday (10/27) | 11:15am |
| jMaki: Multiple Languages, Multiple Toolkits | Room 4204 | Saturday (10/27) | 1:45pm |
Venue: Foothill College, Los Altos Hills, CA
In the first session (Metro), I'll show how Metro enables interoperability with .NET 3.0 platform. The talk shows how a Secure and Reliable Web service deployed on GlassFish V2 can be invoked from Excel 2007 spreadsheet. It also shows how such a Web service can be easily built using NetBeans 6 IDE.
The second talk explains how jMaki provides a light-weight framework to build Ajax-enabled applications using standard practices and using the best toolkits and libraries. Using multiple demos, it shows how this framework spans multiple languages.
Aaron promised to distribute some nice goodies if you attend these two talks :)
Technorati: conf siliconvalleycodecamp metro webservices interoperability jmaki web2.0 glassfish netbeans
Posted by Arun Gupta in webservices | Comments[6]
|
|
|
|
|
Monday October 22, 2007
Boycott yaari.com - "Spam 2.0"
![]() |
This is a "Web 2.0" world so I join different community sites (such as facebook, linkedin, orkut etc.) in order to be not left behind :) One such site happen to be yaari.com which brought me embarrassment instead of any apparent benefit. |
After I registered with their website, it sent an email of the following format to random set of addresses from my GMail address book:
Subject: Arun is your Yaar!
:)
Date: Sat, 13 Oct 2007 10:51:15 -0500
From: Arun MY_EMAIL_ID
Reply-To:
admin@yaari.com
To: EMAIL-ID FROM GMAIL
Arun
San Jose
Arun Gupta wants you to join Yaari!
Is Arun your friend?
Yes <http://www.yaari.com/y-register.php?i=SOME_WEIRD_NUMBER> No
<http://www.yaari.com/y-register.php>
Please respond or Arun might think you said no :(
To stop receiving emails from Yaari.com, click here
<http://yaari.com/y-email-opt-out.php?param=YET_ANOTHER_WEIRD_NUMBER>.
If you have any concerns regarding the content of this message, please email
abuse@yaari.com.
Yaari LLC, 358 Angier Ave, Atlanta, GA 30312
I apologize for unknowingly sending a message from my account.
This is absolute shame. The website says "social networking site created by Indian youth, for Indian youth". I really don't care who has created the website but this is complete invasion of privacy. Stop it yaari.com and get some real work done!
If you get an invitation to join yaari.com, send it back to the original sender along with the link to this blog. An already created account can be deleted by going to Accounts tab and selecting "Deactivate Account" and, of course, never joining back.
Read more horrid experiences here and here.
Boycott yaari.com image used from Aalaap.com. I could not inline the image for an unknown reason.
Posted by Arun Gupta in General | Comments[57]
|
|
|
|
|
Friday October 19, 2007
Mid West Java Tech Days 2007 - Chicago Trip Report
Mid West Java Tech Days concluded in Chicago yesterday.
With approximately 160 participants, the conference attendees were slightly larger in number than the Minneapolis Tech Days. The interaction with the audience was also good. The day started with Tim Bray's key note and it was a repeat of Minneapolis.
I delivered two talks (same as in Minneapolis)- "Metro: Web services interoperability with Microsoft .NET" and "jMaki: Framework for Ajax-enabled Web 2.0 apps". Here are the questions (with answers) that were asked during the presentation:
Metro: Web services interoperability with Microsoft .NET
jMaki: Framework for Ajax-enabled Web 2.0 apps
Here is the picture album:
And I met one my avid blog readers - Roman Kuzmik. He was pretty excited to meet me and it's great to hear you like the content produced on this blog :)
Next stop Silicon Valley Code Camp (Nov 27-28).
Technorati: conf webservices glassfish metro jmaki netbeans
Posted by Arun Gupta in webservices | Comments[2]
|
|
|
|
|
Thursday October 18, 2007
Crowne Plaza Chicago O'Hare - Thumbs Up
I arrived Chicago yesterday for Sun Mid West Java Tech Days.
The stay at The Crowne Plaza Hotel Chicago O'Hare, although just one night, but was just the way I like it. Everything from checking into the hotel to checking out this morning was great. There were minor things which made the stay a pleasant one:
Definitely would recommend to stay there on your next visit to Chicago.
Technorati: conf crowneplaza chicago traveltips
Posted by Arun Gupta in General | Comments[1]
|
|
|
|
|
Tuesday October 16, 2007
Mid West Java Tech Days 2007 - Minneapolis Trip Report
Mid West Java Tech Days concluded in Minneapolis earlier today.
First, here are some facts I learned about Minneapolis:
Second, the Internet connection at the hotel is ridiculously slow (at least for me) as shown here:

I talked to other colleagues staying at the same hotel and it seemed to work fine for them. Anyway, it took 6 calls to the Tech Support to resolve the issue partly. Or may be it's 1:15am in the morning here, the usage is down and that's why I'm seeing a better response time ;-) But when I explained the issue to the hotel, they happily removed the ISP charges for my first day stay @ the hotel.
Now back to the event.
The event kick started with Tim Bray's keynote.
Tim Bray gave the keynote to an audience of approx 125 people and talked about "Business and Cultural aspect of Web 2.0" and "Programming Language and Infrastructure". Everybody in the room raised a hand when asked if they were a developer which was kind of cool because typically we see a mix of IT managers, Engineering Managers, Sys Admins and of course Developers.
One of the key messages in the talk was to start thinking about outside-in (how the community is going to interact/provide feedback about the product) and inside-out (how open the discussions can be) for a product and see how the community can be involved.
Tim presented Tree View of the Programming Languages. It shows how different programming languages are getting adopted year-by-year. The data is created by collecting book purchasing data from different publishers and then taggin each book with language. They point to notice is that only JavaScript and Ruby are growing. Here are some of the points that he mentioned about PHP & Rails:
PHP
Rails
Java is a 3-legged stool comprising of APIs, JVM and Java language. All the scripting languages (Ruby, PHP, JavaScript, etc) are supported in the JVM using JSR 223 APIs.
Tim also compared PHP, Rails and Java in terms of scaling, dev speed, dev tools & maintainability. The talk concluded by stating that Single Architecture IT shop is never going away. PHP, Java, Ruby, .NET - all will continue to exist and live together. REST allows a cleaner integration of these technologies. In my talk on Metro, I discussed an alternate strategy for a heterogeneous systems where Java and .NET can co-exist with each using WS-*-based interoperability achieved in GlassFish.
I delivered two talks - "Metro: Web services interoperability with Microsoft .NET" and "jMaki: Framework for Ajax-enabled Web 2.0 apps".
The first talk (Metro) was scheduled to start at 11:15 am and there were only 3 people in the room at that time. I started the talk few minutes late giving time for people to show up but even by 11:25 (after I've done the initial introductions) there were only approx 12 people in the room. And then somebody from the audience mentioned that the previous session just finished and I did see a splurge of audience right around that time. On audience's request, I did a recap and then continued with rest of the presentation. I was glad that the room was full in few more minutes :)
The slides are available here. Here is the list of questions asked with their answers:
The jMaki talk was SRO and we had to borrow multiple chairs from another room to accommodate the audience. The slides are available here. Here is the list of questions asked with their answers:
And, of course, there were some Hudson enthusiasts.
The evening concluded with a great dinner at Solera along with Charlie, Thomas, Tim and Greg and some interesting discussions about scripting languages.
Here is the picture album so far:
Next step Chicago on Oct 18, there is still time to register!
Technorati: conf webservices glassfish metro jmaki netbeans hudson
Posted by Arun Gupta in webservices | Comments[79]
|
|
|
|
| TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
The current Rails Gem (version 1.2.5) gives an error when creating a Controller in a JRuby-on-Rails application on Windows. It gives the following error during controller creation as shown below:
C:/testbed/ruby/jruby-1.0.1/lib/ruby/1.8/pathname.rb:420:in
`realpath_rec': No such file or directory -C:/testbed/ruby/jruby-1.0.1/samples/rails/hello/C:
(Errno::ENOENT)
from C:/testbed/ruby/jruby-1.0.1/lib/ruby/1.8/pathname.rb:453:in
`realpath'
from C:/testbed/ruby/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/initializer.rb:543:in
`set_root_path!'
from C:/testbed/ruby/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/initializer.rb:509:in
`initialize'
from ./script/../config/boot.rb:35:in `new'
from ./script/../config/boot.rb:35:in `run'
from ./script/../config/boot.rb:35
from :1:in `require'
from :1
and Rails 1.2.4 gives exactly the same error. This is Ticket #9893. This actually happens because of JRUBY-1401.
The workaround is to use Rails 1.2.3. If you have already installed the latest Rails plugin, then you can uninstall it using the command:
C:\testbed\ruby\jruby-1.0.1\bin>gem uninstall rails
Successfully uninstalled rails version 1.2.5
Remove executables and scripts for
'rails' in addition to the gem? [Yn] y
Removing rails
And then install Rails 1.2.3 as:
gem install rails --include-dependencies --version 1.2.3
--no-ri --no-rdoc
Successfully installed rails-1.2.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3
Now create a new application as shown below:
jruby -S rails hello
And then create a controller as:
jruby script\generate controller say hello
exists app/controllers/
exists app/helpers/
create app/views/say
exists test/functional/
create app/controllers/say_controller.rb
create test/functional/say_controller_test.rb
create app/helpers/say_helper.rb
create app/views/say/hello.rhtml
Hope you find it useful and this bug is fixed in the next version of Rails.
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totd rubyonrails jruby windows
Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
| Web 2 Summit - Cool Applications on Industry-grade Operating System
![]() |
Sun Microsystems is a gold sponsor of Web 2 Summit (nee Web 2.0 Conference). Registration to this conference by invitation only. If you are an attendee, here is one session that you don't want to miss: |
In this session, Sun Chief OS Platform Strategist Ian Murdock, Joyent CTO Jason Hoffman and Director of Systems Ben Rockwood will show that the latest innovations in operating system technology are happening in OpenSolaris and will explore how even though the OS is invisible to developers much of the time, it very much still matters for writing cool "Web 2.0" applications.
Technorati: conf opensolaris web2summit web2.0
Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Monday October 15, 2007
Metro and jMaki in Minneapolis and Chicago - Oct 16 & 18 (FREE Event)
![]() |
I'll be presenting on Metro
and jMaki @
Mid West Java Tech Days.
This FREE event is is intended for developers and technologist
interested in expanding their use and application of Java in their
current projects and day-to-day development. Register for Minneapolis (Oct 16) here and Chicago (Oct 18) here. |
Both the talk will show how NetBeans IDE provides a great development environment and GlassFish provides a robust deployment platform for creating secure, reliable, transactional and .NET 3.0 interoperable Web services using Metro. And how to create rich Internet applications using jMaki.
Come by and say hello before/after the talk if you read this blog :)
Technorati: conf metro webservices jmaki glassfish netbeans
Posted by Arun Gupta in webservices | Comments[4]
|
|
|
|
|
Friday October 12, 2007
TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows
In a previous entry, I posted instructions on how to setup Mongrel cluster for JRuby-on-Rails applications on Unix-based systems. The instructions specified there do not work on Windows-based systems because of the following reasons:
So if you want JRuby-on-Rails applications to deploy on Mongrel on Windows, then the workaround is to checkout the JRuby trunk and use Rails 1.2.3. This blog explains the instructions on how to do that. The Mongrel cluster cannot be configured on JRuby yet though.
As a side note, repeated invocation of "jruby" command will
encounter JRUBY-1350.
The workaround is to exit out of the current command prompt and execute the
commands in a new one.
mkdir jruby-trunk
cd jruby-trunk
svn co http://svn.codehaus.org/jruby/trunk/jruby
antjruby-trunk/bin to your PATH.C:\workspaces\jruby-trunk\bin>jruby -J-Xmx384m -S gem install
rails --version 1.2.3 --include-dependencies --no-ri --no-rdoc
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.2.3
Successfully installed rake-0.7.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3C:\workspaces\jruby-trunk\bin>jruby -S gem install gem_plugin
--no-ri --no-rdoc
Successfully installed gem_plugin-0.2.2C:\workspaces\jruby-trunk\bin>jruby -S gem install
cgi_multipart_eof_fix --no-ri --no-rdoc
Successfully installed cgi_multipart_eof_fix-2.3C:\workspaces\jruby-trunk\bin>jruby -S gem install
mongrel-1.0.1-jruby.gem --no-ri --no-rdoc
Successfully installed mongrel, version 1.0.1
Make sure to invoke the command from the directory where the
gem is downloaded.mongrel_cluster
does not work with JRuby and
mongrel_jcluster does not work on Windows. So Mongrel
clusters cannot be configured on a Windows machine.
jruby-trunk\samples\rails and
create a new Rails application as shown below:C:\workspaces\jruby-trunk\samples\rails>..\..\bin\jruby -S rails
hello
create
create app/controllers
create app/helpers
create app/models
...
create log/production.log
create log/development.log
create log/test.logC:\workspaces\jruby-trunk\samples\rails\hello>..\..\..\bin\jruby
script\server
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no
restart).
** Rails signals registered. HUP => reload (without restart). It might
not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.http://localhost:3000
and shows the default "Welcome Aboard You're riding the Rails!" page.
Hit Ctrl-C to stop Mongrel as shown below:** INT signal received.
Exiting
C:/workspaces/jruby-trunk/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in
`const_missing': Mongrel::StopServer (Mongrel::StopServer)
from C:/workspaces/jruby-trunk/lib/ruby/gems/1.8/gems/mongrel-1.0.1-jruby/lib/mongrel.rb:723:in
`run'
from C:/workspaces/jruby-trunk/lib/ruby/gems/1.8/gems/mongrel-1.0.1-jruby/lib/mongrel/configurator.rb:271:in
`initialize'
Terminate batch job (Y/N)? yAn alternative to this behemoth configuration and lack of Mongrel cluster on Windows is to create a Web ARchive (WAR) of your JRuby-on-Rails application and deploy on GlassFish. A complete screencast of how this can be achieved using NetBeans IDE is shown here. A comprehensive list of JRuby on GlassFish documentation is available here.
Technorati: totd rubyonrails jruby ruby mongrel windows jrubyonglassfish glassfish netbeans
Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
|
Thursday October 11, 2007
TOTD #12: Invoking a Java EE 5 Web service endpoint from JRuby
A user asked how to invoke a Java EE 5 Web service from JRuby. This TOTD explains how a simple Metro Web service deployed on GlassFish V2 can be easily invoked from JRuby.
wsimport as shown
below:C:\workarea\samples\jruby\ws>\testbed\glassfish\final\glassfish\bin\wsimport.bat
-keep http://localhost:8080/WebApplication32/HelloService?wsdl
parsing WSDL...
generating code...
compiling code...C:\workarea\samples\jruby\ws>set CLASSPATH=.;\testbed\glassfish\final\glassfish\lib\webservices-rt.jar;\testbed\glassfish\final\glassfish\lib\endorsed\webservices-api.jar;C:\testbed\glassfish\final\gl
assfish\lib\activation.jarinclude Java
service = Java::server.HelloService.new();
port = service.getHelloPort();
result = port.sayHello("Duke");
java.lang.System.out.println(result);C:\workarea\samples\jruby\ws>\testbed\ruby\jruby-1.0.1\bin\jruby
simple.rb
Hello DukeThat's it! Read more about Tooling Options in Metro.
Using Java classes in JRuby explain the issues that you may encounter in invoking Java classes from JRuby.
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totd jruby jrubyonglassfish glassfish netbeans metro webservices ruby
Posted by Arun Gupta in webservices | Comments[0]
|
|
|
|
|
Wednesday October 10, 2007
TOTD #11: Setup Mongrel cluster for JRuby-on-Rails applications on Unix
This TOTD explains the steps to setup a Mongrel cluster for JRuby-on-Rails applications on a Unix flavor operating system. These instructions do NOT work on Windows. A similar post for Windows is cooking and will be posted when ready.
Download JRuby 1.0.1 and unzip the bundle (say JRUBY_HOME).
For convenience, include JRUBY_HOME/bin to
your PATH.
Install the required RubyGems
Install Rails as shown below:
jruby -S gem install rails --version 1.2.3 --include-dependencies
--no-ri --no-rdoc
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.2.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3
Before installing Mongrel, install the pre-requisite
Gems as shown below (see discussion
here):
jruby -S gem install gem_plugin --no-ri --no-rdoc
Successfully installed gem_plugin-0.2.2
and another one:
jruby -S gem install cgi_multipart_eof_fix --no-ri --no-rdoc
Successfully installed cgi_multipart_eof_fix-2.3
Mongrel cannot be installed as a gem on JRuby yet. So
download Mongrel gem and install it as shown below:
jruby -S gem install mongrel-1.0.1-jruby.gem --no-ri --no-rdoc
Successfully installed mongrel, version 1.0.1
Make sure to invoke the command from the directory where the gem is
downloaded.
Install Mongrel cluster. mongrel_cluster
does not work with JRuby and so instead
mongrel_jcluster needs to be installed as shown below:
jruby -S gem install mongrel_jcluster --include-dependencies --no-ri
--no-rdocAs mentioned
here,
Successfully installed mongrel_jcluster-0.0.1
mongrel_jcluster is still quite experimental and
not guaranteed to work in any way but it worked for this post :)
Create a template application say in JRUBY_HOME/samples as
shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails 1954 $ ../../bin/jruby
-S rails hello
create
create app/controllers
create app/helpers
create app/models
...
create log/production.log
create log/development.log
create log/test.log
Start Mongrel as shown below:
cd hello
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $ ../../../bin/jruby
script/server
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on
http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT =>
stop (no restart).
** Rails signals registered. HUP => reload (without restart). It
might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
The application is now available at http://localhost:3000. Hit
Ctrl-C to stop Mongrel as shown below:
^C** INT signal received.
Exiting
/home/arung/testbed/jruby-1.0.1/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:498:in
`require': Mongrel::StopServer (Mongrel::StopServer)
from /home/arung/testbed/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
from /home/arung/testbed/jruby-1.0.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from /home/arung/testbed/jruby-1.0.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from :1
Configure and Start Mongrel cluster
Configure Mongrel cluster as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $
../../../bin/jruby -S mongrel_rails jcluster::configure -p 8000 -N 2
Writing configuration file to config/mongrel_cluster.yml.
This starts a cluster of 2 Mongrels (identified by -N 2)
assigning ports in the ascending order starting at 8000 (identified by
-p 8000).
Start Mongrel cluster as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $
../../../bin/jruby -S mongrel_rails jcluster::start
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
Starting JRuby server...
Starting 2 Mongrel servers...
Now your application is available on
http://localhost:8000 and http://localhost:8001. All the
logs (for all the instances) are available in log/development.log.
The cluster can be stopped as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $ ../../../bin/jruby -S
mongrel_rails jcluster::stop
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
Stopping 2 Mongrel servers...
A follow up post will show how to front-end this cluster of Mongrels with a light-weight HTTP server.
An alternative to this behemoth configuration is to create a Web ARchive (WAR) of your JRuby-on-Rails application and deploy on GlassFish. A complete screencast of how this can be achieved using NetBeans IDE is shown here. A comprehensive list of JRuby on GlassFish documentation is available here.
Technorati: totd rubyonrails jruby mongrel unix jrubyonglassfish glassfish netbeans ruby
Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Thursday October 04, 2007
Screencast #Web 9: JRuby-on-Rails standalone and shared WARs in GlassFish
![]() |
Are you an existing GlassFish V2
user and interested in using Rails applications ? -
JRuby module is
now available on the
Update Center. This module allows you to create standalone or
shared WAR of a Rails application that can be easily deployed on
GlassFish. Read the complete details
here. A screencast following these steps is available here. |
A comprehensive list of JRuby on GlassFish documentation is available here.
Technorati: rubyonrails jruby glassfish updatecenter jrubyonglassfish screencast ruby
Posted by Arun Gupta in web2.0 | Comments[15]
|
|
|
|
|
Today's Page Hits: 143
Total # blog entries: 1002