Miles to go …

November 27, 2008

GlassFish and MySQL Student Contest – Winners announced

Filed under: General — arungupta @ 5:00 am

GlassFish and MySQL student contest winners are announced!

Kolli Bharath from Dhirubhai Ambani Institute of Information and Communication Technology, India (review, project) and Tomas Augusto Muller, Universidade de Santa Cruz do Sul, Brazil (review, project) won the grand prize of $500 each. There are 7 second prize winners of $250 each.

Congratulations to all the winners!

Meet some of the contest participants here, here, here, and here.

There were lots of great entries and picking one was a tough decision. But luckily the process was simple and clearly defined for all the judges. Each submission was assigned numbers between 1-100 in 8 pre-defined criteria and then a winner was picked. Now, don’t ask us about the total marks for each entry or the winning margin ;)

Thanks to all the judges for reviewing the entries!

Here are some guidelines I followed during the review:

  • I looked at the blog and project website, how do I get started ?
  • Is the project site well structured, with links to code, docs, etc ?
  • Is there an installation/user manual ?
  • Is the application a stereotype
  • Is testing (unit, integration, stress, reliability, performance and others) integral part of the project ?
  • Is it a simple JSP/Servlet application or any creative use of GlassFish ? For example, is the participant using Web services, Grizzly Comet, Rails, Grails, Admin console, Monitoring or any such features.
  • Any usability or functionality bugs filed during project development ?
  • How useful is the application in context ?
  • Any NetBeans- or Eclipse-GlassFish integration features used ?

So if you plan to participate in any contest in the future, keep these points in mind :)

If you are interested in advertising your contest entry on this blog, leave a comment on this blog!

Watch out blogs.sun.com/students for upcoming contests.

Technorati: glassfish mysql students spotlight contest

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 26, 2008

TOTD #57: Jersey Client API – simple and easy to use

Filed under: General — arungupta @ 5:00 am

TOTD #56 explains how to create a RESTful Web service endpoint using Jersey and publish the resource using JSON representation. The blog entry showed how the endpoint can be accessed from a Web browser. This Tip Of The Day explains how to use Jersey Client APIs to invoke the published endpoint.

Lets get started!

  1. Create a new directory “./src/test/java/org/glassfish/samples”
  2. Add a test
    1. Add a template test file “AppTest.java” as shown below:

      package org.glassfish.samples;

      import junit.framework.Test;
      import junit.framework.TestCase;
      import junit.framework.TestSuite;

      /**
       * Unit test for simple App.
       */
      public class AppTest
          extends TestCase
      {
          /**
           * Create the test case
           *
           * @param testName name of the test case
           */
          public AppTest( String testName )
          {
              super( testName );
          }

          /**
           * @return the suite of tests being tested
           */
          public static Test suite()
          {
              return new TestSuite( AppTest.class );
          }

          /**
           * Rigourous Test :-)
           */
          public void testApp()
          {
              assertTrue(true);
          }
      }

    2. Add a new method “createResource()” as:
          private WebResource createResource() {
              Client client = Client.create();
              WebResource resource = client.resource(“http://localhost:8080/helloworld-webapp/webresources/myresource”);
              return resource;
          }

      This code creates a default instance of Jersey Client and creates a Web resource from that client for the URI passed as an argument.

    3. Change the implementation of “testApp()” method as:
              Greeting result = createResource().get(Greeting.class);
              assertTrue(result.greeting.equals(“Hi there!”));

      This invokes the GET method on the resource by passing specific type and compares the returned and expected value.

    4. Add the following “imports”:
      import com.sun.jersey.api.client.Client;
      import com.sun.jersey.api.client.WebResource;
    5. Copy “Greeting.java” from TOTD #56 to ”./src/test/java/org/glassfish/samples” directory.
  3. Run the test
    1. Deploy the endpoint as “mvn glassfish:run”.
    2. Run the test as “mvn test”. The following output is shown:
      ~/samples/jersey/helloworld-webapp >mvn test
      [INFO] Scanning for projects…
      [INFO] ————————————————————————
      [INFO] Building helloworld-webapp Jersey Webapp
      [INFO]    task-segment: [test]
      [INFO] ————————————————————————
      [INFO] [resources:resources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:compile]
      [INFO] Nothing to compile – all classes are up to date
      [INFO] [resources:testResources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:testCompile]
      [INFO] Compiling 1 source file to /Users/arungupta/samples/jersey/helloworld-webapp/target/test-classes
      [INFO] [surefire:test]
      [INFO] Surefire report directory: /Users/arungupta/samples/jersey/helloworld-webapp/target/surefire-reports

      ——————————————————-
       T E S T S
      ——————————————————-
      Running org.glassfish.samples.AppTest
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.587 sec

      Results :

      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

      [INFO] ————————————————————————
      [INFO] BUILD SUCCESSFUL
      [INFO] ————————————————————————
      [INFO] Total time: 4 seconds
      [INFO] Finished at: Mon Nov 24 16:50:17 PST 2008
      [INFO] Final Memory: 18M/43M
      [INFO] ————————————————————————

  4. View request and response messages
    1. Change the implementation of “createResource()” method as (changes highlighted in bold):

              Client client = Client.create();
              WebResource resource = client.resource(“http://localhost:8080/helloworld-webapp/webresources/myresource”);
              resource.addFilter(new LoggingFilter());
              return resource;
    2. Running the tests as “mvn test” now shows the output, with request and response messages, as shown below:
      Running org.glassfish.samples.AppTest
      1 * Out-bound request
      1 > GET http://localhost:8080/helloworld-webapp/webresources/myresource
      1 >
      1 < 200
      1 < X-Powered-By: Servlet/2.5
      1 < Transfer-Encoding: chunked
      1 < Content-Type: application/json
      1 < Server: GlassFish/v3
      1 < Date: Tue, 25 Nov 2008 07:07:51 GMT
      1 <
      {“greeting”:”Hi there!”}
      1 * In-bound response
      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.074 sec

Really easy!

Even though the APIs are used to invoke a RESTful endpoint deployed using Jersey but are very generic and can be used to invoke any RESTful endpoint. Paul’s blog explain in detail on the usage. You can also see how these APIs can be used to consume a service hosted using Apache Abdera.

com.sun.jersey.api.client, com.sun.jersey.api.client.config, and com.sun.jersey.api.client.filter packages documents all the classes that provide support for client-side communication with HTTP-based RESTful Web services.

Technorati: totd glassfish v3 embeddable jersey jsr311 rest json webservices

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 25, 2008

TOTD #56: Simple RESTful Web service using Jersey and Embeddable GlassFish – Text and JSON output

Filed under: webservices — arungupta @ 5:00 am


Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services in the GlassFish community. It also provides an API that allows developers to extend Jersey to suite their requirements.

This Tip Of The Day (TOTD) shows how to create a simple RESTful Web service using Jersey and run it using embeddable GlassFish (glassfish:run). Maven is used to create and run the application. It also shows how the output format can be easily coverted from Text to JSON.

Lets get started!

  1. Create a simple web app using Maven as:

    ~/samples/jersey >mvn archetype:generate -DarchetypeCatalog=http://download.java.net/maven/2
    [INFO] Scanning for projects…
    [INFO] Searching repository for plugin with prefix: ‘archetype’.
    [INFO] ————————————————————————
    [INFO] Building Maven Default Project
    [INFO]    task-segment: [archetype:generate] (aggregator-style)
    [INFO] ————————————————————————
    [INFO] Preparing archetype:generate
    [INFO] No goals needed for project – skipping
    [INFO] Setting property: classpath.resource.loader.class => ‘org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader’.
    [INFO] Setting property: velocimacro.messages.on => ‘false’.
    [INFO] Setting property: resource.loader => ‘classpath’.
    [INFO] Setting property: resource.manager.logwhenfound => ‘false’.
    [INFO] [archetype:generate]
    [INFO] Generating project in Interactive mode
    [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
    Choose archetype:
    1: remote -> jersey-quickstart-grizzly (Archetype for creating a RESTful web application with Jersey and Grizzly)
    2: remote -> jersey-quickstart-webapp (Archetype for creating a Jersey based RESTful web application WAR packaging)
    Choose a number:  (1/2): 2
    [INFO] snapshot com.sun.jersey.archetypes:jersey-quickstart-webapp:1.0.1-SNAPSHOT: checking for updates from jersey-quickstart-webapp-repo
    Define value for groupId: : org.glassfish.samples
    Define value for artifactId: : helloworld-webapp
    Define value for version:  1.0-SNAPSHOT: :
    Define value for package: : org.glassfish.samples
    Confirm properties configuration:
    groupId: org.glassfish.samples
    artifactId: helloworld-webapp
    version: 1.0-SNAPSHOT
    package: org.glassfish.samples
     Y: :
    [INFO] —————————————————————————-
    [INFO] Using following parameters for creating OldArchetype: jersey-quickstart-webapp:1.0.1-SNAPSHOT
    [INFO] —————————————————————————-
    [INFO] Parameter: groupId, Value: org.glassfish.samples
    [INFO] Parameter: packageName, Value: org.glassfish.samples
    [INFO] Parameter: package, Value: org.glassfish.samples
    [INFO] Parameter: artifactId, Value: helloworld-webapp
    [INFO] Parameter: basedir, Value: /Users/arungupta/samples/jersey
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] ********************* End of debug info from resources from generated POM ***********************
    [INFO] OldArchetype created in dir: /Users/arungupta/samples/jersey/helloworld-webapp
    [INFO] ————————————————————————
    [INFO] BUILD SUCCESSFUL
    [INFO] ————————————————————————
    [INFO] Total time: 21 seconds
    [INFO] Finished at: Mon Nov 24 14:09:27 PST 2008
    [INFO] Final Memory: 12M/30M
    [INFO] ————————————————————————
  2. Edit the generated “pom.xml” to add dependencies on GlassFish plugin
    1. Add the following plugin in the “pom.xml” under <build>/<plugins>:

                  <plugin>
                      <groupId>org.glassfish</groupId>
                      <artifactId>maven-glassfish-plugin</artifactId>
                  </plugin>
    2. Add the following plugin repositories:
          <pluginRepositories>
              <pluginRepository>
                  <id>maven2-repository.dev.java.net</id>
                  <name>Java.net Repository for Maven</name>
                  <url>http://download.java.net/maven/2/</url>
                  <layout>default</layout>
              </pluginRepository>
              <pluginRepository>
                  <id>maven-repository.dev.java.net</id>
                  <name>Java.net Maven 1 Repository (legacy)</name>
                  <url>http://download.java.net/maven/1</url>
                  <layout>legacy</layout>
              </pluginRepository>
          </pluginRepositories>
    3. Optionally, if the generated dependencies in “pom.xml” as shown below:
              <dependency>
                  <groupId>org.glassfish.distributions</groupId>
                  <artifactId>web-all</artifactId>
       
                 <version>10.0-build-20080430</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.glassfish.embedded</groupId>
                  <artifactId>gf-embedded-api</artifactId>
                  <version>1.0-alpha-4</version>
                  <scope>test</scope>
              </dependency>

      are changed to:

              <dependency>
                  <groupId>org.glassfish.distributions</groupId>
                  <artifactId>web-all</artifactId>
                  <version>10.0-SNAPSHOT</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                 <groupId>org.glassfish.embedded</groupId>
                 <artifactId>glassfish-embedded-all</artifactId>
                 <version>3.0-Prelude-SNAPSHOT</version>
              </dependency>

      then the latest version of Embedded GlassFish APIs are used.

    4. Also optionally, if you want to run against Jersey 1.0 bits then change the following property from “1.0.1-SNAPSHOT” to “1.0″.
          <properties>
              <jersey-version>1.0</jersey-version>
          </properties>
  3. Run the application
    1. The generated source code is:

      package org.glassfish.samples;

      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;

      // The Java class will be hosted at the URI path “/helloworld”
      @Path(“/myresource”)
      public class MyResource {
         
          // The Java method will process HTTP GET requests
          @GET
          // The Java method will produce content identified by the MIME Media
          // type “text/plain”
          @Produces(“text/plain”)
          public String getIt() {
              return “Hi there!”;
          }
      }

      Invoking “mvn glassfish:run” starts the embedded GlassFish and shows the following output:

      ~/samples/jersey/helloworld-webapp >mvn glassfish:run
      [INFO] Scanning for projects…
      [INFO] Searching repository for plugin with prefix: ‘glassfish’.
      [INFO] ————————————————————————
      [INFO] Building helloworld-webapp Jersey Webapp
      [INFO]    task-segment: [glassfish:run]
      [INFO] ————————————————————————
      [INFO] Preparing glassfish:run
      [INFO] [resources:resources]
      [INFO] Using default encoding to copy filtered resources.
      [INFO] [compiler:compile]
      [INFO] Compiling 1 source file to /Users/arungupta/samples/jersey/helloworld-webapp/target/classes
      [INFO] [glassfish:run]
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: HK2 initialized in 229 ms
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: com.sun.enterprise.naming.impl.ServicesHookup@2470b02c Init done in 237 ms
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: com.sun.enterprise.v3.server.Globals@13b3d787 Init done in 239 ms
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: com.sun.enterprise.v3.server.SystemTasks@61bedd7d Init done in 244 ms
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: com.sun.enterprise.v3.services.impl.HouseKeeper@2b9f7952 Init done in 245 ms
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: com.sun.enterprise.v3.services.impl.CmdLineParamProcessor@5249d560 Init done in 248 ms
      JMXMP connector server URL = service:jmx:jmxmp://localhost:8888
      Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
      INFO: Listening on port 8080
      Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: com.sun.enterprise.v3.services.impl.GrizzlyService@1baa56a2 startup done in 551 ms
      Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.services.impl.ApplicationLoaderService postConstruct
      INFO: loader service postConstruct started at 1227566166208
      Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: Application Loader startup done in 740 ms
      Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: Glassfish v3 started in 740 ms
      Nov 24, 2008 2:36:07 PM com.sun.enterprise.web.WebModuleContextConfig authenticatorConfig
      SEVERE: webModuleContextConfig.missingRealm
      Nov 24, 2008 2:36:07 PM com.sun.jersey.api.core.PackagesResourceConfig init
      INFO: Scanning for root resource and provider classes in the packages:
        org.glassfish.samples
      Nov 24, 2008 2:36:07 PM com.sun.jersey.api.core.PackagesResourceConfig init
      INFO: Root resource classes found:
        class org.glassfish.samples.MyResource
      Nov 24, 2008 2:36:07 PM com.sun.jersey.api.core.PackagesResourceConfig init
      INFO: Provider classes found:
      Hit ENTER for redeploy

      Notice how GlassFish v3 starts up in sub-second (740 ms in this case).

    2. “http://localhost:8080/helloworld-webapp” shows the following output:

    3. Clicking on “Jersey resource” redirects to “http://localhost:8080/helloworld-webapp/webresources/myresource” and shows the following output:

  4. Change the output representation to produce JSON representation
    1. Add a new JAXB bean:

      package org.glassfish.samples;

      import javax.xml.bind.annotation.XmlRootElement;

      /**
       * @author arungupta
       */
      @XmlRootElement
      public class Greeting {
          public String greeting;

          public Greeting() { }
          public Greeting(String greeting) {
              this.greeting = greeting;
          }
      }

    2. Change the method implementation in MyResource as:
      //    @Produces(“text/plain”)
          @Produces(“application/json”)
          public Greeting getIt() {
              return new Greeting(“Hi there!”);
          }
    3. And now “http://localhost:8080/helloworld-webapp/webresources/myresource” shows the following output:

      Notice the output is now in JSON format.

  5. Optionally a WAR file can be created using the command:
    mvn clean package

    and the WAR file is generated in “target/helloworld-webapp.war”. If Jersey is installed using GlassFish v3 Update Center then you can use “maven-assembly-plugin” to customize packaging of WAR and drastically reduce the size.

The JSON representation can be configured in multiple ways as explained in Configuring JSON for RESTful Web Services in Jersey 1.0. This has certainly come a long way from TOTD #8 and is much more effecient now.

The Jersey Wiki documents an extensive set of resources to get started.

Send all your questions to .

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. An archive of all the tips is available here.

Technorati: totd glassfish v3 embeddable jersey jsr311 rest json webservices

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 24, 2008

LOTD #14: New Whitepaper: GlassFish High Availability Reference Configurations for a Virtualized Environment

Filed under: General — arungupta @ 5:00 am


GlassFish v2 allows you to configure cluster of multiple nodes/instances to meet various availability requirements, from the highly scalable service availability configuration to the business-critical, 99.999% service-and-data availability configuration. A cluster can be deployed using different toplogies with a choice of service/data availability, in-Memory/HADB, co-located/non-colocated and other factors. This new white paper explains reference configurations on that can be used for deploying business services.

Access it here!

All previous entries in this series are archived at LOTD.

Technorati: lotd glassfish clustering whitepaper

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 21, 2008

TOTD #55: How to build GlassFish v3 Gem ?

Filed under: web2.0 — arungupta @ 5:00 am

GlassFish Gem is a light-weight and robust deployment solution for Ruby-on-Rails and Merb applications. The gem can be easily installed as:

gem install glassfish

for any JRuby runtime. Support for other Rack-based frameworks such as Sinatra is coming soon!

This Tip Of The Day (TOTD) explains how to build this gem if you like to understand the internals or hack it out:

svn co https://svn.dev.java.net/svn/glassfish-scripting/trunk/rails/v3/gem gem
cd gem
mvn -U clean install

And the generated gem is available at:

./target/dependency/glassfish/pkg/glassfish-0.9.0-universal-java.gem

Simple and easy!

TOTD #52 explains how gem can be used to run Rails or Merb applications.

Are you using GlassFish gem ? File bugs @ RubyForge and send feedback to GlassFish Webtier Forum.

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. An archive of all the tips is available here.

Technorati:  totd glassfish v3 gem rubyonrails jruby

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 20, 2008

TOTD #54: Java Server Faces with Eclipse IDE

Filed under: web2.0 — arungupta @ 5:00 am

Ed pointed me to this excellent tutorial that explains how JavaServer Faces applications can be easily created using Eclipse IDE. The article clearly shows all the steps to create a Java Server Faces application and demonstrates the following JSF concepts:

  • How to register managed beans to a JSF application ?
  • Different templates for creating JSF pages
  • Validators
  • Resource Bundles
  • Navigation rules in faces-config.xml (very intuitive and easy-to-use)
  • Dependency injection
  • Value and Method Binding

Few code/snapshot mismatches but knowing that it’s only version 0.3, it’s a damn good job!

Couple of differences from the article:

First, I deployed all the samples on GlassFish v3 Prelude which has Mojarra 1.2 baked in. The screencast #28 explains how to configure GlassFish with Eclipse IDE.

Secondly, instead of using WTP, I used Eclipse 3.4 for Java EE developers which has built-in support for JSF 1.1 and 1.2 applications. So there is no need to download/configure JSP/JSTL libraries. Instead the libraries are specified during project creation as shown below:

And then let the server side provide JSF implementation by selecting radio button as shown below:

That’s it, now the Mojarra baked in GlassFish v3 Prelude is used for JSF runtime.

The faces-config editor is really cool, intuitive and easy-to-use. Here is a snapshot:

Here is a snapshot of the project explorer window (package names are different from the original article):

And now finally the outputs from 4 JSF applications:

All of this using Mojarra and GlassFish v3 Prelude :)

Let us know your feedback on Mojarra at GlassFish Webtier forum, file bugs in Issue Tracker, and find the latest information about Mojarra at javaserverfaces.dev.java.net.

Technorati: totd javaserverfaces eclipse glassfish v3 mojarra

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 19, 2008

Screencast #28: Simple Web Application using Eclipse and GlassFish v3 Prelude

Filed under: web2.0 — arungupta @ 5:00 am

GlassFish v3 Prelude is now available! Some of the cool features are:

  • Modularity using OSGi
  • Rapid deployment using retain session data across HTTP redeploys and deploy-on-save
  • Embeddability
  • Dynamic languages and frameworks
  • Faster start up time
  • Integrated NetBeans and Eclipse tooling
  • Comet and Cometd

This screencast shows how you can create a simple Web application using JSP and Servlets in Eclipse 3.4, deploy it directly on GlassFish v3, use rapid deployment, and debug the application.


The GlassFish plugin for Eclipse has many more features than demonstrated in this screencast and are explained here.

A complete list of GlassFish related screencasts is available here. Other screencasts published on this blog are available here.

Also see GlassFish v3 running using Equinox, Rails and Merb applications using GlassFish Gem, and Embeddable GlassFish.

Submit your bugs Eclipse/GlassFish bugs here, talk to us using GlassFish Plugins Forum, and get the latest information on glassfishplugins.dev.java.net.

Technorati: screencast glassfish v3 eclipse jsp servlets deployonsave deployment

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 18, 2008

TOTD #53: Scaffold in Merb using JRuby/GlassFish

Filed under: web2.0 — arungupta @ 5:00 am

GlassFish Gem 0.9.0 can be used to run Rails and Merb applications. Support another Rack-based framework Sinatra is coming up in the near future. This blog shows how to create a scaffold in Merb and run it using the GlassFish gem.

Merb allows pluggable ORM and comes with DataMapper as the default one. However DataMapper has native dependencies and so cannot be used with JRuby. There is discussion about creating a DataMapper adapter over JDBC but in the meanwhile ActiveRecord is the only ORM that can be used with JRuby.

Merb wiki has extensive documentation but lacks clearly defined steps for generating scaffold when using ActiveRecord. This blog fulfills those gaps and provides a comprehensive tutorial to build a Merb scaffold.

  1. Lets create a Merb application using ActiveRecord ORM as:

    ~/samples/jruby/merb >~/tools/jruby-1.1.5/bin/jruby -S merb-gen core –orm activerecord hello
    Generating with core generator:
         [ADDED]  gems
         [ADDED]  merb.thor
         [ADDED]  .gitignore
         [ADDED]  public/.htaccess
         [ADDED]  doc/rdoc/generators/merb_generator.rb
         [ADDED]  doc/rdoc/generators/template/merb/api_grease.js
         [ADDED]  doc/rdoc/generators/template/merb/index.html.erb
         [ADDED]  doc/rdoc/generators/template/merb/merb.css
         [ADDED]  doc/rdoc/generators/template/merb/merb.rb
         [ADDED]  doc/rdoc/generators/template/merb/merb_doc_styles.css
         [ADDED]  doc/rdoc/generators/template/merb/prototype.js
         [ADDED]  public/favicon.ico
         [ADDED]  public/merb.fcgi
         [ADDED]  public/robots.txt
         [ADDED]  public/images/merb.jpg
         [ADDED]  Rakefile
         [ADDED]  app/controllers/application.rb
         [ADDED]  app/controllers/exceptions.rb
         [ADDED]  app/helpers/global_helpers.rb
         [ADDED]  app/views/exceptions/not_acceptable.html.erb
         [ADDED]  app/views/exceptions/not_found.html.erb
         [ADDED]  autotest/discover.rb
         [ADDED]  autotest/merb.rb
         [ADDED]  autotest/merb_rspec.rb
         [ADDED]  config/init.rb
         [ADDED]  config/rack.rb
         [ADDED]  config/router.rb
         [ADDED]  config/environments/development.rb
         [ADDED]  config/environments/production.rb
         [ADDED]  config/environments/rake.rb
         [ADDED]  config/environments/staging.rb
         [ADDED]  config/environments/test.rb
         [ADDED]  public/javascripts/application.js
         [ADDED]  public/stylesheets/master.css
         [ADDED]  spec
         [ADDED]  app/views/layout/application.html.erb
  2. Generate a Merb resource (model, controller and associated things):
    ~/samples/jruby/merb/hello >merb-gen resource Runner distance:float,minutes:integer
    Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
    Generating with resource generator:
    Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
    Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
    Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
    Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
         [ADDED]  spec/models/runner_spec.rb
         [ADDED]  app/models/runner.rb
         [ADDED]  schema/migrations/001_runner_migration.rb
         [ADDED]  spec/requests/runners_spec.rb
         [ADDED]  app/controllers/runners.rb
         [ADDED]  app/views/runners/index.html.erb
         [ADDED]  app/views/runners/show.html.erb
         [ADDED]  app/views/runners/edit.html.erb
         [ADDED]  app/views/runners/new.html.erb
         [ADDED]  app/helpers/runners_helper.rb
    resources :runners route added to config/router.rb

    As evident from the generated files Model, Controller, Helper and Views are generated. The Views are only template files with no code because this code end up getting changed anyway most of the times. Instead template Views can be written as explained in CRUD View Examples (more on this later).

  3. Configure Database
    1. Merb applications do not have a pre-generated “database.yml” so create one as:

      ~/samples/jruby/merb/hello >rake db:create
      (in /Users/arungupta/samples/jruby/merb/hello)
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
      Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
      Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
      Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
       ~ It took: 0
       ~ Loading: Merb::BootLoader::MixinSession
       ~ It took: 0
       ~ Loading: Merb::BootLoader::BeforeAppLoads
       ~ It took: 0
      &nbsp
      ;~ Loading: Merb::Orms::ActiveRecord::Connect
       ~ No database.yml file found in /Users/arungupta/samples/jruby/merb/hello/config.
       ~ A sample file was created called database.yml.sample for you to copy and edit.
    2. Copy “config/database.yml.sample” to “config/database.yml”. Wonder why this step is explicitly required ?
    3. Edit database configuration such that it looks like:
      :development: &defaults
        :adapter: mysql
        :database: hello_development
        :username: root
        :password:
        :host: localhost
        :socket: /tmp/mysql.sock
        :encoding: utf8

      The changed lines are shown in bold.

    4. Create the database as:
      ~/samples/jruby/merb/hello >rake db:create
      (in /Users/arungupta/samples/jruby/merb/hello)
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
      Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
      Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
      Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
       ~ It took: 0
       ~ Loading: Merb::BootLoader::MixinSession
       ~ It took: 0
       ~ Loading: Merb::BootLoader::BeforeAppLoads
       ~ It took: 0
       ~ Loading: Merb::Orms::ActiveRecord::Connect
       ~ Connecting to database…
       ~ It took: 0
       ~ Loading: Merb::BootLoader::LoadClasses
       ~ It took: 0
       ~ Loading: Merb::BootLoader::Router
       ~ Compiling routes…
       ~ It took: 0
       ~ Loading: Merb::BootLoader::Templates
       ~ It took: 0
       ~ Loading: Merb::BootLoader::MimeTypes
       ~ It took: 0
       ~ Loading: Merb::BootLoader::Cookies
       ~ It took: 0
       ~ Loading: Merb::BootLoader::SetupSession
       ~ It took: 1
       ~ Loading: Merb::BootLoader::SetupStubClasses
       ~ It took: 0
       ~ Loading: Merb::BootLoader::AfterAppLoads
       ~ It took: 0
       ~ Loading: Merb::BootLoader::ChooseAdapter
       ~ It took: 0
       ~ Loading: Merb::BootLoader::RackUpApplication
       ~ It took: 0
       ~ Loading: Merb::BootLoader::ReloadClasses
       ~ It took: 0
      DEPRECATION WARNING: You’re using the Ruby-based MySQL library that ships with Rails. This library will be REMOVED FROM RAILS 2.2. Please switch to the offical mysql gem: `gem install mysql`  See http://www.rubyonrails.org/deprecation for details. (called from mysql_connection at /Users/arungupta/tools/jruby-1.1.5/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/connection_adapters/mysql_adapter.rb:81)
       ~   SQL (0.000581)   SET NAMES ‘utf8′
       ~   SQL (0.000581)   SET SQL_AUTO_IS_NULL=0
       ~   SQL (0.000894)   CREATE DATABASE `hello_development` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_general_ci`
      MySQL hello_development database successfully created
    5. Migrate the database as:
      ~/samples/jruby/merb/hello >rake db:migrate
      (in /Users/arungupta/samples/jruby/merb/hello)
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
      Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
      Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb
      Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb
       ~ It took: 0
       ~ Loading: Merb::BootLoader::MixinSession
       ~ It took: 0
       ~ Loading: Merb::BootLoader::BeforeAppLoads
       ~ It took: 0
       ~ Loading: Merb::Orms::ActiveRecord::Connect
       ~ Connecting to database…
       ~ It took: 0
       ~ Loading: Merb::BootLoader::LoadClasses
       ~ It took: 1
       ~ Loading: Merb::BootLoader::Router
       ~ Compiling routes…
       ~ It took: 0
       ~ Loading: Merb::BootLoader::Templates
       ~ It took: 0
       ~ Loading: Merb::BootLoader::MimeTypes
       ~ It took: 0
       ~ Loading: Merb::BootLoader::Cookies
       ~ It took: 0
       ~ Loading: Merb::BootLoader::SetupSession
       ~ It took: 0
       ~ Loading: Merb::BootLoader::SetupStubClasses
       ~ It took: 0
       ~ Loading: Merb::BootLoader::AfterAppLoads
       ~ It took: 0
       ~ Loading: Merb::BootLoader::ChooseAdapter
       ~ It took: 0
       ~ Loading: Merb::BootLoader::RackUpApplication
       ~ It took: 0
       ~ Loading: Merb::BootLoader::ReloadClasses
       ~ It took: 0
      DEPRECATION WARNING: You’re using the Ruby-based MySQL library that ships with Rails. This library will be REMOVED FROM RAILS 2.2. Please switch to the offical mysql gem: `gem install mysql`  See http://www.rubyonrails.org/deprecation for details. (called from mysql_connection at /Users/arungupta/tools/jruby-1.1.5/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/connection_adapters/mysql_adapter.rb:81)
       ~   SQL (0.000769)   SET NAMES ‘utf8′
       ~   SQL (0.000610)   SET SQL_AUTO_IS_NULL=0
       ~   SQL (0.001609)   SHOW TABLES
       ~   SQL (0.003952)   CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
       ~   SQL (0.054355)   CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
       ~   SQL (0.001691)   SHOW TABLES
       ~   SQL (0.001643)   SELECT version FROM schema_migrations
       ~ Migrating to RunnerMigration (1)
      == 1 RunnerMigration: migrating ===============================================
      — create_table(:runners)
       ~   SQL (0.005301)   CREATE TABLE `runners` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `distance` float, `minutes` int(11), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
         -> 0.0107s
      == 1 RunnerMigration: migrated (0.0114s) ======================================

       ~   SQL (0.014063)   INSERT INTO schema_migrations (version) VALUES (’1′)
       ~   SQL (0.003585)   SHOW TABLES
       ~   SQL (0.001324)   SELECT version FROM schema_migrations
       ~   SQL (0.001451)   SHOW TABLES
       ~   SQL (0.017054)   SHOW FIELDS FROM `runners`
       ~   SQL (0.018503)   describe `runners`
       ~   SQL (0.009372)   SHOW KEYS FROM `runners`

  4. Create the CRUD views
    1. Add dependencies
      1. Edit “config/init.rb” and add the following line:

        require ‘config/dependencies.rb’

        as the first uncommented line.

      2. Create “config/dependencies.rb” and add the following dependency (explained here):
        dependency “merb-assets”, “1.0″
        dependency “merb-helpers”, “1.0″
    2. Add the resource routes by editing “config/router.rb” and adding:
      resources :runners

      insider “Merb::Router.prepare do” block.

    3. Edit the “index” view in “app/views/runners/index.html.erb” as:
      <h1>Runner controller, index action</h1>

      <table>
        <tr>
          <th>Distance (in miles)</th>
          <th>Time (in mins)</th>

          <th colspan=”3″>Actions</th>
        </tr>

      <% @runners.each do |runner| %>
        <tr>
          <td><%=h runner.distance %></td>
          <td><%=h runner.minutes %></td>

          <td><%= link_to ‘Show’, resource(runner) %></td>
          <td><%= link_to ‘Edit’, resource(runner, :edit) %></td>
          <td><%= delete_button(runner, “Delete #{runner.distance}”) %></td>
        </tr>
      <% end %>
      </table>

      <%= link_to ‘New’, resource(:runners, :new) %>

    4. Edit the “new” in “app/views/runners/new.html.erb” view as:
      <h1>Runners controller, new action</h1>

      <%= form_for(@runner, :action => resource(:runners) ) do %>
       
        <p>
          <%= text_field :distance, :label => “Distance (in miles)” %>
        </p>
       
        <p>
          <%= text_field :minutes, :label => “Time (in mins)”  %>
        </p>
       
        <p>
          <%= submit “Create” %>
        </p>
      <% end =%>
       
      <%= link_to ‘Back’, resource(:runners) %>

    5. Edit the “show” view in “app/views/runners/show.html.erb” as:
      <h1>Runners controller, show action</h1>

      <p>Distance (in miles): <%=h @runner.distance %></p>
      <p>Time (in mins): <%=h @runner.minutes %></p>
       
      <%= link_to ‘Back’, resource(:runners) %>

    6. Edit the “edit” in “app/views/runners/edit.html.erb” view as:
      <h1>Runners controller, edit action</h1>

      <%= form_for(@runner, :action => resource(@runner)) do %>
       
        <p>
          <%= text_field :distance, :label => “Distance (in miles)”  %>
        </p>
       
        <p>
          <%= text_field :minutes, :label => “Time (in mins)”  %>
        </p>
       
        <p>
          <%= submit “Update” %>
        </p>
      <% end =%>
       
      <%= link_to ‘Show’, resource(@runner) %> | <%= link_to ‘Back’, resource(:runners) %>

That’s it!

And now here are some of the captured outputs.

The default output at “http://localhost:3000/runners”

Creating a new Runner at “http://localhost:3000/runners/new” as:

“Show” view of a runner at “http://localhost:3000/runners/<id>” as :

“Index” view with one runner at “http://localhost:3000/runners” as:

And now “index” view with 2 runners at “http://localhost:3000/runners” as:

A Merb app generated using MRI can also be run using GlassFish, provided it does not have any native dependencies.

And another useful piece of information is difference between Rails and Merb provide comparative syntax between Rails and Merb.

And thanks to all the discussion on merb@googlegroups where all my questions were answered very promptly!

Submit your bugs here, talk to us using GlassFish Forum, and get the latest information on JRuby wiki.

Technorati: totd glassfish v3 gem jruby rubyonrails merb

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 17, 2008

GlassFish @ JavaMUG – Trip Report

Filed under: General — arungupta @ 4:00 am

Presented on GlassFish at Java MUG last week. The event is hosted at Sun‘s North Dallas Office. It was impressive to know that local Sun team is hosting 4 User Groups (MySQL, Solaris, and OpenSolaris other than the JUG) in a month.

The evening started around 6pm when the attendees started showing up for socializing over Pizza and Soda. The JUG started with a brief introduction by Eric Weibust – the JUG leader. The community leaders from Spring User Group, Dallas Rules Group, and SOA Users Group then gave an update in their user groups.

After the sponsor‘s pitch, I explained What/Why/How of GlassFish. The slides are available here. It was pretty exciting when 100% of attendees have heard about GlassFish. A few of them are using it for development as well and now we need to work on getting some production deployments there :)

The demos showed in the talk can be accessed at:

  • Rapid Deployment using deploy-on-save for JSP/Servlets
  • Rails develop/run/debug using NetBeans
  • Secure, Reliable, Transactional, and .NET-interoperable Web service

Here are some pictures:

And then the complete album:

Thanks for showing up and listening about GlassFish. I’m catching up on email and will start responding to the requests from JUG attendees!

Technorati: conf glassfish jug javamug dallas

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

November 14, 2008

TOTD #52: Getting Started with Merb using GlassFish Gem

Filed under: web2.0 — arungupta @ 9:35 am

GlassFish Gem 0.9.0 was recently released. It can run any Rack-compatible framework such as Rails and Merb. Support for another Rack-based framework Sinatra will be released in the near future. The gem is even extensible and allows to plug any of your favorite Ruby framework using -apptype switch (more on this in a future blog). This blog shows how to install the gem and use it for running a Merb application.

Lets install the gem first:

~/tools/jruby-1.1.5 >gem install glassfish rack
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed glassfish-0.9.0-universal-java
Successfully installed rack-0.4.0
2 gems installed
Installing ri documentation for glassfish-0.9.0-universal-java…
Installing ri documentation for rack-0.4.0…
Installing RDoc documentation for glassfish-0.9.0-universal-java…
Installing RDoc documentation for rack-0.4.0…

The Rack dependency will be fixed as part of the next gem update and for now we have to install it explicitly. The different options supported by the gem can be seen using “-h” switch as:

~/tools/jruby-1.1.5 >glassfish -h

Synopsis
——–
glassfish: GlassFish v3 server for rails, merb, sintra applications

Usage:
——
glassfish [OPTION] APPLICATION_PATH

-h, –help:             show help

-c, –contextroot PATH: change the context root (default: ‘/’)

-p, –port PORT:        change server port (default: 3000)

-e, –environment ENV:  change rails environment (default: development)

-n –runtimes NUMBER:   Number of JRuby runtimes to crete initially

–runtimes-min NUMBER:  Minimum JRuby runtimes to crete

–runtimes-max NUMBER:  Maximum number of JRuby runtimes to crete

APPLICATION_PATH (optional): Path to the application to be run (default:
current).

And complete rdocs are available here.

Lets create and run a Merb application!

  1. Install Merb: Merb 1.0 has some native dependencies in DataMapper and so cannot be installed as is with JRuby. However since Merb is ORM-agnostic, ActiveRecord can be installed as ORM layer. “gem install merb” uses DataMapper as the default ORM so a Merb installation in JRuby (for now) is:

    ~/tools/jruby-1.1.5 >gem install merb-core merb-more merb_activerecord
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Successfully installed extlib-0.9.8
    Successfully installed abstract-1.0.0
    Successfully installed erubis-2.6.2
    Successfully installed json_pure-1.1.3
    Successfully installed rack-0.4.0
    Successfully installed mime-types-1.15
    Successfully installed thor-0.9.8
    Successfully installed merb-core-1.0
    Successfully installed ZenTest-3.11.0
    Successfully installed RubyInline-3.8.1
    Successfully installed sexp_processor-3.0.0
    Successfully installed ParseTree-3.0.2
    Successfully installed ruby2ruby-1.2.1
    Successfully installed merb-action-args-1.0
    Successfully installed merb-assets-1.0
    Successfully installed merb-slices-1.0
    Successfully installed merb-auth-core-1.0
    Successfully installed merb-auth-more-1.0
    Successfully installed merb-auth-slice-password-1.0
    Successfully installed merb-auth-1.0
    Successfully installed merb-cache-1.0
    Successfully installed merb-exceptions-1.0
    Successfully installed highline-1.5.0
    Successfully installed diff-lcs-1.1.2
    Successfully installed templater-0.4.0
    Successfully installed merb-gen-1.0
    Successfully installed haml-2.0.4
    Successfully installed merb-haml-1.0
    Successfully installed merb-helpers-1.0
    Successfully installed mailfactory-1.4.0
    Successfully installed merb-mailer-1.0
    Successfully installed merb-param-protection-1.0
    Successfully installed addressable-1.0.4
    Successfully installed data_objects-0.9.6
    Successfully installed dm-core-0.9.6
    Successfully installed dm-migrations-0.9.6
    Successfully installed merb_datamapper-1.0
    Successfully installed merb-more-1.0
    Successfully installed merb_activerecord-0.9.13
    39 gems installed
    Installing ri documentation for json_pure-1.1.3…
    Installing ri documentation for rack-0.4.0…
    Installing ri documentation for mime-types-1.15…
    . . .
    Installing RDoc documentation for dm-migrations-0.9.6…
    Installing RDoc documentation for merb_datamapper-1.0…
    Installing RDoc documentation for merb_activerecord-0.9.13…

    It would be nice if this can be further simplified to “gem install merb –orm activerecord” or something similar.

  2. Create a Merb application:  A “jump start” Merb application created using “merb-gen app” uses ERB templating and DataMapper for ORM. But as mentioned earlier DataMapper does not work with JRuby (at least for now) so a Merb application needs to be created using “merb-gen core”. This command creates a Merb application with Ruby-on-Rails like structure and allows to plugin templating engine and ORM frameworks.

    Lets create our first Merb application with no ORM and default templating engine as:

    ~/samples/jruby/merb >merb-gen core hello
    Generating with core generator:
         [ADDED]  gems
         [ADDED]  merb.thor
         [ADDED]  .gitignore
         [ADDED]  public/.htaccess
         [ADDED]  doc/rdoc/generators/merb_generator.rb
         [ADDED]  doc/rdoc/generators/template/merb/api_grease.js
         [ADDED]  doc/rdoc/generators/template/merb/index.html.erb
         [ADDED]  doc/rdoc/generators/template/merb/merb.css
         [ADDED]  doc/rdoc/generators/template/merb/merb.rb
         [ADDED]  doc/rdoc/generators/template/merb/merb_doc_styles.css
         [ADDED]  doc/rdoc/generators/template/merb/prototype.js
     &nbs
    p;   [ADDED]  public/favicon.ico
         [ADDED]  public/merb.fcgi
         [ADDED]  public/robots.txt
         [ADDED]  public/images/merb.jpg
         [ADDED]  Rakefile
         [ADDED]  app/controllers/application.rb
         [ADDED]  app/controllers/exceptions.rb
         [ADDED]  app/helpers/global_helpers.rb
         [ADDED]  app/views/exceptions/not_acceptable.html.erb
         [ADDED]  app/views/exceptions/not_found.html.erb
         [ADDED]  autotest/discover.rb
         [ADDED]  autotest/merb.rb
         [ADDED]  autotest/merb_rspec.rb
         [ADDED]  config/init.rb
         [ADDED]  config/rack.rb
         [ADDED]  config/router.rb
         [ADDED]  config/environments/development.rb
         [ADDED]  config/environments/production.rb
         [ADDED]  config/environments/rake.rb
         [ADDED]  config/environments/staging.rb
         [ADDED]  config/environments/test.rb
         [ADDED]  public/javascripts/application.js
         [ADDED]  public/stylesheets/master.css
         [ADDED]  spec
         [ADDED]  app/views/layout/application.html.erb

    ActiveRecord can be used as pluggable ORM by using the command “merb-gen core –orm activerecord hello”. A future blog will cover creating a Merb scaffold using ActiveRecord.

  3. Create a new controller as:
    ~/samples/jruby/merb/hello >merb-gen controller Runners
    Loading init file from /Users/arungupta/samples/jruby/merb/jruby-1.1.5/samples/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/jruby-1.1.5/samples/merb/hello/config/environments/development.rb
    Generating with controller generator:
    Loading init file from /Users/arungupta/samples/jruby/merb/jruby-1.1.5/samples/merb/hello/config/init.rb
    Loading /Users/arungupta/samples/jruby/merb/jruby-1.1.5/samples/merb/hello/config/environments/development.rb
         [ADDED]  app/controllers/runners.rb
         [ADDED]  app/views/runners/index.html.erb
         [ADDED]  spec/requests/runners_spec.rb
         [ADDED]  app/helpers/runners_helper.rb

    Notice the convention of controller name is a plural word and starting with a capital letter.

  4. Edit application
    1. Edit “app/controllers/runners.rb” and change the “index” action such that it looks like:

        def index
          @message = “Miles to go …”
          render
        end
    2. Edit “app/views/runners/index.html.erb” and add “<br><%= @message %>” as the last line.
  5. Run application:  Running a Merb application using the Gem is pretty straight forward. If JRUBY_HOME/bin is in PATH, just type the command “glassfish” in the application directory and now you are running a Merb application using GlassFish. The application is accessible at “http://localhost:3000″ and the output looks like:

    The controller is accessible at “http://localhost:3000/runners” and the output is:

Hit Ctrl+C to stop the application.

A Merb app generated using MRI can also be run using GlassFish, provided it does not have any native dependencies. On my MacBook, I had to update gems (gem update –system) and install XCode.

This same gem can be used to run Rails application, and guess what? That is pretty straight forward too. Just type “glassfish” in the application directory and now you are running a Rails application on GlassFish. These applications can very well be created using MRI but they must be using pure-Ruby gems/plugins. Alternatively Foreign Function Interface can be used to port your native gems to Ruby.

Lets make it more real by running Substruct – an open source E-Commerce project. Install it as explained here, type “glassfish” in the application directory and your application is now accessible at “http://localhost:3000″ as shown below:

Really simple, easy and powerful!

Rails powered by GlassFish explains the benefits of running Rails application on GlassFish. And now GlassFish v3 Prelude allows you to even buy production support for your Rails applications! Screencast #26 how to develop/run/debug your Rails application using NetBeans and GlassFish.

Open Source Rails has a gallery of open source Rails projects, have you tried any of them ?

Is there any Merb equivalent of www.opensourcerails.com ?

Technorati: totd glassfish v3 gem rubyonrails merb rack

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Older Posts »

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress