Friday Mar 09, 2007

Groovy Gravy ?

I think so.

This debate about language preferences can get religious and being an atheist I know how that goes ;) That's not so to say that Groovy is the only religion language that should exist. Horses for courses, right ? But, I think Groovy is good. How good ? Well - really good. Off the cuff in no particular order here's why:

  • Groovy code compile to Java bytecodes - Java tool support, Java Security, Java EE ...
  • Syntax is simple - code more maintainable
  • MOP (Meta Object Protocol) - enables some wicked maneuvers
  • In-built XML support - unbelievable how simple it is to read/write XML
  • Groovy has Grails !
  • ... and more. You can find the entire feature set on the Groovy site.
Currently only Rhino, a JavaScript interpreter, is bundled with Java SE 6. The Java platform is capable of integrating with any script engine conforming to JSR 223, and it can't possible bundle ?-too-many scripting engines out of the box, but Groovy and (the language) Java seem to be a perfect fit. Is the Groovy gravy spicy enough for Java's palate ? I hope so ...

Thursday Feb 15, 2007

RoRaWAR - A War Roar ?

No, it's not a war roar. This is not a current world affairs blog ;)

RoRaWAR stands for Ruby on Rails as Web ARchive.

The rails integration (under the jruby-extras umbrella) project's purpose is to WAR'up a RoR application. And it's great to see how far the project has come along since its inception a few months ago !

The creation of a web archive from a RoR application is as simple as

  • svn checkout svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration rails-integration
  • cd rails-integration; mvn install;

  • the couple of steps above are one time only

  • cp -R <rails-integrations>/plugins/war <rails-app-dir>/vendor/plugins/
    cp -R <rails-integrations>/plugins/war-snapshot/\* <rails-app-dir>/vendor/plugins/war
  • cd <rails-app-dir>; rake war:standalone:create or rake war:shared:create ;
    #standalone mode will archive the rails framework libraries whereas the shared mode will not
It's as simple as that !

Note: There are a few implied dependencies here - JRuby, maven2, rails framework libraries. Also, since the rails-integration project is trying to utilize the latest and greatest JRuby releases, you might have to install the jruby.jar into maven2 repository via the maven install:install-file command. Eventually, the first couple of steps will not be needed once the rails-integration libraries are downloadable as a binary release, but until then ...

Wednesday Jan 24, 2007

Grizzlicious ... Part II

Part I described how to get a RoR application working on GlassFish. However, if you want something lightweight for development only or do not want anything to do with configuration changes(which btw, will only get simpler) or any other reason, read on ...

The elegant design of Grizzly allows you to write just a few lines of code and have a custom HTTP server suited to your specific requirements. The rails module does just that for primarily running a RoR application. This is how:

  1. Download rails-module-0.1-SNAPSHOT.jar
  2. The latest Grizzly binaries
  3. And of course, the JRuby binaries, Rails framework libraries and database specific JDBC drivers. For JRuby, I recommend working with the current trunk version as there are issues with the 0.9.2 release and the rails-module. Copy plaincharset.jar(in ${JRUBY_HOME}/lib) to jre/lib/ext of your Java runtime. For installing the Rails framework including activerecord-jdbc see steps #3 and #4. Use the flags(--no-rdoc --no-ri) for faster gem installation.

    Steps 1,2 and 3 are one time only.

  4. Create the Rails applications. Perform the following edits
    • Database related configuration edits - db config and step #8 here
    • In config/development.rb set config.breakpoint_server to false. See JRuby issue for more details.
  5. That's it ! Run it as something like
    # set the CLASSPATH variable to include
    # rails-module, grizzly, JDBC driver, 
    # JRuby libs(jruby.jar, jvyaml, asm, jline and jruby-openssl)
    java -classpath ${CLASSPATH} -Djruby.base=${JRUBY_HOME}
        com.sun.grizzly.rails.standalone.Main ${RAILS_ROOT}
    
    Or download the script and modify it to run in your environment.

Friday Jan 19, 2007

Grizzlicious ... RoR on GlassFish

In some of the previous episodes, I described how to go about deploying a Ruby on Rails(RoR) application on GlassFish. The first post described the method of deployment in which the RoR application is packaged as a WAR file, whereas the later posts(here and here) utilized the native Ruby interpreter at runtime(RoR-as-WAR runs on JRuby).

However, both deployment models are not quite ideal for a production deployment scenario. Enter Grizzly ! The NIO based HTTP connector for GlassFish. The beauty of Grizzly is not only that it's fast and scalable but that it is also highly extensible. TAKAI Naoto was quick to realize this fact and quickly dished out the first version of the adapter code needed to deploy RoR applications directly on top of Grizzly.

Without further ado, the steps to get a RoR application working as a first-class citizen within GlassFish:

  1. Download and install GlassFish in ${GLASSFISH_HOME}
  2. Download rails-module-0.1-SNAPSHOT.jar to ${GLASSFISH_HOME}/lib
  3. Checkout the latest source of JRuby and build it.
    Copy jruby.jar jvyaml.jar and asm-2.2.2.jar and to ${GLASSFISH_HOME}/lib
  4. Copy plaincharset.jar(in ${JRUBY_HOME}/lib) to jre/lib/ext of your Java runtime installation.
  5. Install the rails libraries including activerecord-jdbc. See step #3, #4 .
  6. The rails applications should installed under ${GLASSFISH_HOME}/domains/${domain-name}/applications/rails and you still need to do edits to get jdbc adapter working with JRuby. See steps #7 and #8 from the previous post
  7. Modify GlassFish configuration (which persists in ${GLASSFISH_HOME}/domains/${domain-name}/config/domain.xml - you could use the great administration UI - typically available at port 4848 via the browser or the command line interface to perform the changes) as below.
    • Add RoR specific http listener
          <http-listener acceptor-threads="1" address="0.0.0.0" 
                blocking-enabled="false" default-virtual-server="server" enabled="true" 
                family="inet" id="http-listener-rails" port="8081"
                security-enabled="false" server-name="" xpowered-by="true">
      
              <property name="selectorThreadImpl" value="com.sun.grizzly.rails.RailsSelectorThread"/>
          </http-listener>
      
    • To the java-config add the system property 'jruby.base'
          <jvm-options>-Djruby.base=jruby-home-value-here</jvm-options>
      
  8. Modify $GLASSFISH_HOME}/domains/${domain-name}/applications/rails/config/environments/development.rb by setting the property config.breakpoint_server to false. Once issue #427 in JRuby is fixed this step will not be needed.
Give it a shot !

Wednesday Dec 06, 2006

RoR in GlassFish with Derby as the database

In my previous post I wrote about getting a RoR application to work on GlassFish as a web application. Since the Derby database is embedded in GlassFish why not try to use it as the backend datastore for the RoR-web-application.

Getting a Ruby on Rails application to work with a Derby database should be relatively straightforward. Well it is, but only after you've jumped through a few hoops trying to figure things out for the first time.

1. Modify config/database.yml to something like:

development:
 adapter: jdbc
 driver: org.apache.derby.jdbc.ClientDriver
 url: jdbc:derby://${database host}:${database port}/${database name}
 username: ${username}
 password: ${password}
Derby has the concept of 'database name' and 'schema'. If 'schema' is unspecified it defaults to 'username'

2. Create table(s) in Derby. Points to note here are:
   2.1 Use upper case for all table/column names
   2.2 To create the auto increment identifier column use the following SQL statement

CREATE TABLE ${table-name} ( ID INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, ${other-columns-and-constraints} )


I'm not sure what the SQL standard is on auto increment column types but this was bit of a pain to figure out. Also remember that 'DESC' is a reserved work in SQL terminology so do not use that as a column name.

The Derby jdbc driver should by default be in the classpath of GlassFish application server so no tweaking needed on that account. However, if you are running the RoR application on JRuby/WEBrick combo you'll need to add the derby-jdbc-driver library to the classpath.

That's pretty much all there is to it. Give it a shot !

About

whacko

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today