Friday Feb 11, 2011

Java wishlist for Windows Azure

TOTD #155 explains how to run GlassFish in Windows Azure. It works but as evident from the blog, its not easy and intuitive. It uses Worker Role to install JDK and GlassFish but the concepts used are nothing specific to Java. Microsoft has released Azure SDK for Java and AppFabric SDK for Java which is a good start but there are a few key elements missing IMHO. These may be known issues but I thought of listing them here while my memory is fresh :-)


Here is my wish list to make Java a better on Windows Azure:

  1. Windows Azure Tools for Eclipse has "PHP Development Toolkit" and "Azure SDK for Java" but no tooling from the Java perspective. I cannot build a Java/Java EE project and say "Go Deploy it to Azure" and then Eclipse + Azure do the magic and provide me with a URL of the deployed project.
  2. Why do I need to configure IIS on my local Visual Studio development for deploying a Java project ?
  3. Why do I have to explicitly upload my JDK to Azure Storage ? I'd love to specify an element in the "ServiceConfiguration" or where ever appropriate which should take care of installing JDK for me in the provisioned instance. And also set JAVA_HOME for me.
  4. Allow to leverage clustering capabilities of application servers such as GlassFish. This will also provide session-failover capabilities on Azure :-)
  5. Sticky session load balancing.
  6. If Windows VM crashes for some reason then App Fabric restarts it which is good. But I'd like my Java processes to be monitored and restarted if they go kaput. And accordingly Load Balancer switches to the next available process in the cluster.
  7. Visual Studio tooling is nice but allow me to automate/script the deployment of project to Azure.
  8. Just like Web, Worker, and VM role - how about a Java role ?
  9. And since this is a wishlist, NetBeans is the best IDE for Java EE 6 development. Why not have a NetBeans plugin for Azure ?
  10. A better integration with Java EE APIs and there are several of them - JPA, Servlets, EJB, JAX-RS, JMS, etc.
  11. The "happy scenario" where every thing works as expected is fine is good but that rarely happens in software development. The availabilty of debugging information is pretty minimal during the "not so happy scenario". Visual Studio should show more information if the processes started during "Launch.ps1" cannot start correctly for some reason.

And I'm not even talking about management, monitoring, adminstration, logging etc.

Thank you Microsoft for a good start with Java on Azure but its pretty basic right now and needs work. I'll continue my exploration!

Christmas is coming later this year ... and I'll be waiting :)

Technorati: windows azure wishlist glassfish netbeans eclipse

Monday Feb 07, 2011

TOTD #155: Run GlassFish in Windows Azure

David Chou blogged about Run Java with GlassFish in Windows Azure ... super! I've been thinking of trying this for sometime and was quite stoked when an initial introduction from Doris and a nudge from me expedited a task pending since past few months. Thanks a lot David for blogging the steps and answering my multiple emails (about 70+ over the past few days :) to help fine tune these steps for the GlassFish community.

This Tip Of The Day (TOTD) will provide detailed steps for running GlassFish in Azure. Lets get started!

  1. Request a free 30-day Windows Azure Pass (or click here). It took me about 15 days between the request and issue of this pass so plan accordingly.
  2. Download and Install the softwares
    1. Download and Install Visual Studio Express.
      1. Install Virtual Clone Drive such that Visual Studio ISO image can be mounted and then installed.
    2. Download and Install Azure SDK and Tools.



      "VCloudService.exe" is the plug-in for Visual Studio and provides integration of Azure tools to Visual Studio. The SDK provides out-of-Visual Studio help so you could do things on the CLI or test the project using Compute and Storage emulator (more on this later).
    3. Install IIS 7.0 on Windows Vista following these instructions.
    4. Make sure to enable "World Wide Web Services", "Application Development Features", ".NET Extensiblity" and "ASP.NET" in Control Panel as shown:

    5. Download JDK 1.6 (latest update) for Windows and install it on a Windows machine.
    6. Download GlassFish 3.1 b40.
  3. Upload installation files to Azure Blob Storage - Upload the GlassFish zip file and JDK installation zip to Azure Blob Storage service. These images will then be used by the Compute Cloud to install JDK and GlassFish during the image initialization.
    1. Using Azure Management Console, create a New Storage Account as shown:


    2. The typical convention is to create multiple containers in Blob Storage and load your application into "apps" container and JDK installer into "java" container. There are several tools that allow you to manage the Azure Storage service such as Neudesic's Azure Storage Explorer and Cerebrata's Cloud Storage Studio. I prefer Cloud Storage Studio because it gave me a nice debug error message when the local Windows machine date/time were too much out of sync with the storage server. However once the error was identified and fixed, Azure Storage Explorer worked as well.

      Note for creating a new account in either of these tools, create a new "Storage Account" using "Azure Management Console", and use "Primary access key" and "Account Name" for account credentials



      This is the same access key specified in the project configuration later. I used GlassFish 3.1 build 40 and installed JDK locally on my machine, made a zip, and then uploaded in the storage. Another option is to silent install JDK.

      Here are snapshots from Azure Storage Explorer after the files are uploaded to Azure Blob Storage:



      Make sure to select "HTTPS" check box when the connection is created. And now Cloud Storage Studio snapshot ...


  4. Create the Visual Studio project
    1. Start Visual Studio using Administrator privileges. This will ensure that service package created later can be deployed to Azure Compute Emulator (used for testing in the local environment) from within the IDE.
    2. Select "File", "New Project ..." and create a cloud-based project by selecting/entering the values as shown:



      and click on "OK".
    3. Create a new worker role as:



      Select "Worker Role", click ">", edit the name to "GlassFishWorker", and click on "OK".
    4. Extract MinimalJavaWorkerRole.zip (from Mario Kosmiska's article) and copy the following files:
      • lib\\ICSharpCode.SharpZipLib.dll
      • Run.cmd
      • Launch.ps1

        from "JettyWorkerRole" to this newly created solution. The updated directory structure looks like:

         
    5. Make sure to save "Launch.ps1" and "Run.cmd" using "Save As...", "Save with encoding" and selecting "Western European (Windows) - Codepage 1252" instead of the default "UTF-8".
    6. Change the properties of the copied files such that these files are copied to output directories for compilation and packaging. In Solution Explorer, right-click on each file and select "Properties" and change the value from "Do not copy" to "Copy always" as shown below:

    7. Edit "Launch.ps1", keep the two pre-defined functions as is and change the text as shown below:

      $connection_string =
      'DefaultEndpointsProtocol=http;AccountName=YOUR-STORAGE;AccountKey=YOUR-KEY'
      
      # JDK
      $jdk = 'jdk1.6.0_23.zip'
      download_from_storage 'java' $jdk $connection_string (Get-Location).Path
      unzip ((Get-Location).Path + "\\" + $jdk) (Get-Location).Path
      
      # GlassFish
      $glassfish = 'glassfish-3.1-b40.zip'
      download_from_storage 'apps' $glassfish $connection_string (Get-Location).Path
      unzip ((Get-Location).Path + "\\" + $glassfish) (Get-Location).Path
      
      # Launch GlassFish
      .\\jdk1.6.0_23\\bin\\java `-jar
      .\\glassfish3\\glassfish\\modules\\admin-cli.jar start-domain --verbose
      
      

      "jdk1.6.0_23.zip" is the name of zipped directory JDK 6 installation uploaded to Azure Blob Storage and similarly "glassfish-3.1-b40.zip" is name of the zip file for your GlassFish 3.1. The latest build of GlassFish 3.1 can always be downloaded from here.
    8. Edit "ServiceDefinition.csdef" to change the service definition and add the following fragment:
      <Startup>
         <Task commandLine="Run.cmd" executionContext="limited"taskType="background" />
      </Startup>
      <Endpoints>
         <InputEndpoint name="Http_Listener_1" protocol="tcp" port="80" localPort="8080" />
         <InputEndpoint name="Http_Listener_2" protocol="tcp" port="8181" localPort="8181" />
         <InputEndpoint name="Http_Listener_3" protocol="tcp" port="4848" localPort="4848" />
         <InputEndpoint name="JMX_Connector_Port" protocol="tcp" port="8686" localPort="8686" />
         <InputEndpoint name="Remote_Debug_Port" protocol="tcp" port="9009" localPort="9009" />
      </Endpoints>
      
      
      as shown below:



      Notice the external "port" for "Http_Listener_1" is 80 and "localPort" is 8080. This ensures that public requests can be received without specifying the port number (80 being the default) and then internally it is routed to port 8080 which is where GlassFish is running anyway. For all others, the same port is exposed.
  5. Deploy the project from Visual Studio, complete steps are described here and the relevant ones are captured below:
    1. Create a new Hosted Service using Azure Management Console by clicking on "New Hosted Service" and entering the details as shown below:



      and click on "OK". If you recall, we set the external port to be 80 and redirecting to local port 8080. With this setup, your requests will be received at "glassfish-service.cloudapp.net:80" or "glassfish-service.cloudapp.net" and redirected to GlassFish 3.1 b40 running on the provisioned instance. Choose the service name carefully as that becomes the URL of your deployed service.
    2. In Solution Explorer, right-click on the project and choose "Publish ..."



      The default operating system provisioned is "Windows Server 2008 SP2" and can be configured by editing "osFamily" and "osVersion" attributes in ServiceConfiguration.csdef. For example changing "osFamily" to "2" will use "Windows Server 2008 R2".
    3. Specify the Credentials as shown below:



      and click on "OK".
    4. Click on "Copy the full path" and then copy the certificate to "Management Certificates" section of the Management Portal.
    5. Select the "production" environment as shown below:



      and click on "OK".
      1. Optionally, you can configure Remote Desktop Connection in case you want to look at the provisioned system later. Here is how the configuration looks like:



        More details about the configuration are described here. Some clarifications on this step ...
        1. The password must contain a mix of lower-case letters, upper-case letters, and numbers or symbols otherwise will not accept it. Just a red icon appears to the right with no indication of the error message.
        2. Certificate Export
          1. After the certificate is created, click on "View ...", "Details" tab, "Copy to file ..." button to copy the generated certificate to a file. This certificate need to be imported in Management Portal.
          2. Make sure to select "Yes, export the private key".
          3. Select "Delete the private key if the export is successful".
        3. Upload this certificate to Management Portal (before publishing the project) as explained in "To upload a certificate using the management portal" here.

          How I could not get this configured successfully and kept getting the error:
          There was no endpoint listening at https://management.core.windows.net/SUBSCRIPTION-ID/services/hostedservices/glassfish-service/deploymentslots/Production
          that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
          
    6. The "Windows Azure Activity Log" displays log as the project is deployed to Azure. The following is displayed once the project is successfully deployed:



      Now you can access the "Website URL" to see:



      And web-based Admin Console is seen as:


This GlassFish instance is the default installation. What would you like to do with it - hack it, break it, deploy apps to it, something else ? :-) I can just right-click in my Visual Studio project and deploy this instance again!

Once again, many many thanks to David Chou for helping me through these steps!

Some TODOs for the future blog entries ...

  1. Create a Java EE 6 application using NetBeans and remote deploy it to this instance.
  2. Try out this installation locally using Azure Compute Emulator and Storage Emulator.
  3. Try debugging Launch.ps1 scripts using Power Shell.
  4. Use JPA to access data in SQL Azure.
  5. Debug SOAPAction error in Remote Desktop Connection.
  6. Windows Azure VM Role feature for JDK installation.
  7. Is ServiceConfiguration extensible ? I'd love to have an attribute in this file take care of JDK/GlassFish installation.
  8. GlassFish 3.1 clustering integrated with Azure Clustering and Load Balancing.

Which one are you going to author ? :-)

Technorati: totd glassfish javaee6 microsoft windows azure cloud

Wednesday Dec 02, 2009

TOTD #114: How to enable Java Console in Mac OS X, Windows, ... ?

Debugging an applet running with Java plug-in or JNLP application running with Java Web Start in the browser requires the "Java Console" so that debugging messages printed using System.out and System.err can be seen. In Windows, there is a "Show Java Console" menu item in Firefox but clicking it still does not show the console. And this happens because the console window is disabled by default.

However the setting can be easily altered as explained below.

On Mac OS, open "Applications" -> "Utilities" -> "Java Preferences"
On Windows, open "Control Panel" -> "Java"
On any platform, type "javaws -viewer"

Click on the "Advanced" tab to see a window similar to the following on Mac OS X:

And the following on Windows:

Change the "Java Console" setting from "Hide console" to "Show console". Launching your JNLP from the browser next time now will also open the "Java Console" as shown below:

and debugging messages will be nicely printed in the console. Read more about the options displayed in the console here.

Technorati: osxtips windows java console jnlp debugging totd

Wednesday Apr 22, 2009

LOTD #21: Production Deployment Tips for running Rails on GlassFish v2 using Windows


SeaChange Affinity uses Rails and GlassFish as their deployment platform. One of their core developers posted tips based upon their experience so far and they are available at:

Rails on GlassFish v2 using Windows

Here are some of the quotes:

Glassfish can really handle a heavy load

and

handling 400 simultaneous users under a supremely heavy load, the memory was holding great

All previous links in this series are archived at LOTD.

Technorati: lotd glassfish jruby rubyonrails windows

Wednesday Feb 11, 2009

TOTD #69: GlassFish High Availability/Clustering using Sun Web Server + Load Balancer Plugin on Windows Vista


TOTD #67 shows how to configure GlassFish High Availability using Apache httpd + mod_jk on Mac OS X. Even though that's a standard and supported configuration, there are several advantages for replacing Apache httpd with Sun Web Server and mod_jk with Load Balancer plugin that comes with GlassFish.

This Tip Of The Day (TOTD) shows how to configure Clustering and Load Balancing using GlassFish v2.1, Sun Web Server, Load Balancer plugin on Windows Vista. This blog is using JDK 6 U7, GlassFish v2.1 (cluster profile), Sun Web Server 7 U4, and Load Balancer plug-in with Sun GlassFish Enterprise Server 2.1 Enterprise Profile (with HADB link).

Lets get started!
  1. Install the required software
    1. Download JDK (if not already installed).
    2. Download and Install GlassFish v2.1. Make sure to configure using "ant -f setup-cluster.xml". This will ensure that the created domain is capable of creating clusters and can perform in-memory session replication for applications deployed on the cluster.
    3. Download and Install Sun Web Server. The process is very simple by unzipping the downloaded bundle, clicking on "setup.exe" and taking all the defaults.
    4. Download GlassFish Enterprise Profile for Load Balancer plugin bits. Start the install by clicking on the downloaded file and select the options as shown below:


    5. Copy the following "loadbalancer.xml" in "https-<host>" (replace <host> with the host name of your machine) directory of Sun Web Server installation directory:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun Java
      System Application Server 9.1//EN"
      "file:///C:/Sun/WebServer7/https-LH-KRKZDW6CJE1V/config/sun-loadbalancer_1_2.dtd
      ">

      <loadbalancer>
       <cluster name="cluster1" policy="round-robin" policy-module="">
        <instance name="instance1" enabled="true"
      disable-timeout-in-minutes="60" listeners="http://localhost:38080" weight="100"/>
        <instance name="instance2" enabled="true"
      disable-timeout-in-minutes="60" listeners="http://localhost:38081" weight="100"/>
        <web-module context-root="/clusterjsp"
      disable-timeout-in-minutes="30" enabled="true" error-url=""/>
        <health-checker interval-in-seconds="7" timeout-in-seconds="5" url="/"/>
       </cluster>
       <property name="response-timeout-in-seconds" value="120"/>
       <property name="reload-poll-interval-in-seconds" value="7"/>
       <property name="https-routing" value="false"/>
       <property name="require-monitor-data" value="false"/>
       <property name="active-healthcheck-enabled" value="false"/>
       <property name="number-healthcheck-retries" value="3"/>
       <property name="rewrite-location" value="true"/>
      </loadbalancer>

      The parameters to be changed are highlighted in bold and explained below:
      1. Sun Web Server installation directory
      2. HTTP port of instances created in the cluster. The ports specified are the default ones and can be found by clicking on the instance as shown below:

      3. Context root of the application that will be deployed in the cluster. The Domain Administration Server (DAS) can be configured to populate this file whenever any application is deployed to the cluster.
  2. Create the cluster as explained in TOTD #67. The admin console shows the following screenshot after the cluster is created and all instances are created/started:

     

    and the following for 2 instances:



  3. Deploy "clusterjsp" as explained in TOTD #67. The admin console shows the following screenshot after "clusterjsp" is deployed:


  4. Start Sun Web Server using "startserv.bat" in "https-<host>" directory.
This concludes the installation and configuration steps, now show time!

Accessing "http://localhost/clusterjsp" shows:



The Sun Web Server is running on port 80 and uses "loadbalancer.xml" to serve the request from the configured instances in <loadbalancer> fragment. This particular page is served by "instance1" as indicated in the image. Lets add session data with property name "aaa" and value "111". The value is shown as:



The instance serving the data, "instance1" in this case, and the session data are highlighted.

Now lets stop "instance1" using the admin console and it looks like:



Click on "RELOAD PAGE" and it looks like:



Exactly same session data is served, this time by "instance2".

The sequence above proves that the session data created by the user is preserved even if the instance serving the data goes down. This is possible because of GlassFish High Availability. The session data is served by the "replica partner" where its already copied using in-memory session replication.

The following articles are also useful:
Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all tips is available here.

Technorati: totd glassfish highavailability clustering loadbalancing lbplugin sunwebserver windows vista

Tuesday Jan 13, 2009

TOTD #65: Windows 7 Beta 1 Build 7000 on Virtual Box: NetBeans + Rails + GlassFish + MySQL


Microsoft released Windows 7 Beta 1 - the next major version of Vista, download here. There are tons of improvments mostly centered around making the content easily & intuitively accessible. But hey, Mac OSX already serves that purpose well for quite some time ;-)

But I still want to make sure that our Rails stack (NetBeans, GlassFish, and MySQL) work fine on it. And it very well do, without any issues, as you'll realize at the end of this blog :)

Lets first get started with installing Windows 7 Beta as a Virtual Box image. Few points to note here:
  • Only IE can be used for downloading Windows 7 Beta, FireFox & Safari on Mac do nothing (confirmed). With a growing share of both Mac and Firefox (TODO: add a link), I think this combination needs to be at least included on their testing matrix. There was no clear way to file bugs but sent feedback using "Send Feedback" button that is omnipresent on top-right corner of each window.
  • The 64-bit Windows 7 installer do not work on Virtual Box 2.1 installed on a 64-bit MacBook Pro. So had to download the 32-bit installer instead :( This seems to be a Virtual Box bug so filed #3027.
  • The 32-bit and 64-bit files are named "7000.0.081212-1400_client_en-us_Ultimate-GB1CULFRE_EN_DVD-32bit.iso" and "7000.0.081212-1400_client_en-us_Ultimate-GB1CULXFRE_EN_DVD.iso" respectively. If you noticed the only difference is the letter "X" before "FRE" . This required a deep look to spot the difference and very non-intuitive. Frankly, I had to put the two names above each other to spot the difference ;-)
Here are my Virtual Box VM settings:


Anyway, after that the install process was pretty simple. Anybody who has previous Windows install experience can vouch the installation mostly  goes seamless, as was the case here. The complete installation using screen snapshots is shown here. Some of the snapshots from my install process are shown below:









Ta da ... after multiple boots during installation, the final welcome screen shows up as following:



Even the beta install required an activation key. The key is shown on the screen after the download. A freshly installed Windows 7 Beta shows the following disk properties:



Lets install our Rails stack.

Download JDK 6 U11 (TODO: check with or w/o NetBeans), MySQL 5.1, NetBeans 6.5 (which includes GlassFish v3 Prelude, JRuby 1.1.4, Rails 2.1, and other goodies)! Alternatively, you can also download JDK 6 U11 + NetBeans 6.5 co-bundle here.

Install them in the same order by double-clicking on the downloaded bundle and taking all default values.

First MySQL installation ...



MySQL is automatically started and registered with Windows as a service.

And then NetBeans installation ...



Because of the default access controls setup in Windows 7 (as in Vista as well), NetBeans need to be run as an administrator by right-clicking, selecting "Run as administrator". Screencast #26 shows to develop, run, and debug a Rails application on GlassFish v3 Prelude. Here are some screen snapshots as the steps outlined in that screencast are performed.

Here is a snapshot that shows how a simple Rails application can be created:



Running the Rails application on GlassFish v3 Prelude ...



And now debugging using the NetBeans IDE ...



Overall, I'm happy with the first experience of Windows 7 Beta 1. The install process was smooth and it was nice to see the picture of a fish on the welcome screen. They can even consider swapping it with a glassfish ;-)

TOTD #64 showed how to install OpenSolaris 2008/11 using Virtual Box and run the same stack there. So be it Windows 7 or Open Solaris 2008/11, you can develop, run, and debug your Rails application with pleasure using NetBeans and GlassFish. And of course, Mac OS X :)

What is your primary Operating System for development ?

Do you use any Virtualization software for trying multiple Operating Systems ? Which one ?

Technorati: totd windows windows7 virtualbox netbeans glassfish mysql rubyonrails jruby

Wednesday Feb 06, 2008

TOTD #25: Rails application with PostgreSQL database using NetBeans

This blog describes how you can create a Rails application accessing PostgreSQL database using NetBeans 6.

  1. Download and Configure PostgreSQL
    1. Download PostgreSQL from here.
    2. After download and install, open the PostgreSQL command prompt (from the program menu) and initialize the database by giving the following command (in bin directory):

      initdb -D "\\users\\Arun Gupta\\postgresql\\data"

      Note, the directory specified in the command does not exist and will be created after the command is executed. The following output is shown:

      The files belonging to this database system will be owned by user "Arun Gupta".
      This user must also own the server process.

      The database cluster will be initialized with locale English_United States.1252.

      fixing permissions on existing directory /users/Arun Gupta/postgresql/data ... ok
      creating subdirectories ... ok
      selecting default max_connections ... 100
      selecting default shared_buffers/max_fsm_pages ... 32MB/204800
      creating configuration files ... ok
      creating template1 database in /users/Arun Gupta/postgresql/data/base/1 ... ok
      initializing pg_authid ... ok
      initializing dependencies ... ok
      creating system views ... ok
      loading system objects' descriptions ... ok
      creating conversions ... ok
      setting privileges on built-in objects ... ok
      creating information schema ... ok
      vacuuming database template1 ... ok
      copying template1 to template0 ... ok
      copying template1 to postgres ... ok

      WARNING: enabling "trust" authentication for local connections
      You can change this by editing pg_hba.conf or using the -A option the
      next time you run initdb.

      Success. You can now start the database server using:

      "postgres" -D "/users/Arun Gupta/postgresql/data"
      or
      "pg_ctl" -D "/users/Arun Gupta/postgresql/data" -l logfile start

      Please note the username shown in the first line of command output ("Arun Gupta" in this case). This will be required later for configuring database.yml.
    3. Start the PostgreSQL by giving the following command:

      "postgres" -D "/users/Arun Gupta/postgresql/data"

      The following output is shown:

      LOG: database system was shut down at 2008-01-10 22:11:01
      LOG: checkpoint record is at 0/4872F8
      LOG: redo record is at 0/4872F8; undo record is at 0/0; shutdown TRUE
      LOG: next transaction ID: 0/593; next OID: 10820
      LOG: next MultiXactId: 1; next MultiXactOffset: 0
      LOG: database system is ready
  2. Create a JRuby-on-Rails project using PostgreSQL
    1. Using NetBeans, create a Rails project. Select PostgreSQL as the database as shown below:

    2. Update the Development database in "database.yml" to match:

      development:
        adapter: postgresql
        host: localhost
        port: 5432
        database: RailsApplication1_Development
        username: Arun Gupta
        password:


      The default port and username are used.
    3. Install a pure-Ruby Postgres database binding by giving the following commands:

      C:\\Program Files\\NetBeans 6.0\\ruby1\\jruby-1.0.2\\bin>jruby gem install postgres-pr
      Bulk updating Gem source index for: http://gems.rubyforge.org
      Successfully installed postgres-pr-0.4.0


      Adding the gem using "Tools" -> "Ruby Gems" encounters the issue #122593.
  3. Do the migrations
    1. Open PostgreSQL command prompt and create the database by giving the following command (in bin directory):

      createdb RailsApplication1_Development

      Note this is case sensitive. The following output is shown:

      CREATE DATABASE
    2. Create a new model by right-clicking on the project, selecting "Generate", "model" from the list box and giving the name as "wish".
    3. Expand "Database Migrations", "migrate" and open "001_create_wishes.rb". Change "self.up" helper method as shown below:

      def self.up
        create_table :wishes do |t|
          t.column :greeting, :string
        end
        Wish.create :greeting => "Hello PostgreSQL!"
      end


      This instructs the Rails framework to a new table and populate it with three rows upon migration.
    4. Invoke db:migrate by right-clicking on the project, selecting "Run Rake Task", "db" and then "migrate". This creates the appropriate tables and populate the it with three rows as mentioned above.
  4. Add Controller & View
    1. Right-click on project, select "Generate...".
    2. Take the default value in list box, which is "controller". Specify the value of "Name:" as "show" and value of "Views:" as "wishes".
    3. Expand "Controllers" and open "show_controller.rb" and update the "wishes" helper method as shown below:

      def wishes
        @wish = Wish.find(1).greeting;
      end
    4. Expand "Views", "show", "wishes.rhtml" and add the following fragment as the last line:

      <%= @wish %>
  5. Run the project
    1. Open "wishes.rhtml" and hit Shift+F6 (default keystroke to run the file). The output is shown as:


       

Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.

Technorati: totd netbeans ruby jruby postgresql windows

Wednesday Dec 19, 2007

OSX #1: Getting Started with a Mac for a Windows User

MacBook Image I got a new Apple MacBook Pro (Intel Core 2 Duo, 2GB RAM, 160 GB HDD and other good stuff) and excited about that! However I've been a Windows user all along and this is my first interaction with a Mac.

So here are some basic tips/tools to get you started if you are in the same situation:

  • Start with Mac101 - This will get you familiar with Mac, basic terminology, some keyboard hints and other misc stuff.
  • Keyboard mappings between a Windows and Mac keyboard are very different. It would help to print out the mappings and keep them handy. It can take more than a day to get used to the new mappings. Some specific ones are:
    • "Right-click"ing is not intuitive - Enable Two-Finger Click on the Trackpad
    • No Forward Delete key, Mac equivalent is Fn + Delete
    • No dedicated Home, Page Up or Page Down keys, Instead use Fn + Cursor keys
  • Install the following tools
Also read 10 tips for Mac users switching from Windows and a more comprehensive list at Switch to The Mac.

The box came installed with Tiger (Mac OSX 10.4) as opposed to Leopard (Mac OS X 10.5). Leopard Updates are available for $9.95 until Jan 4th, 2007.

Some other striking difference in the terms of UI are:

  • The menus, instead of stacked to each window, are always available at the top.
  • "Windows Control Panel" is available as "System Preferences" on Dock (the toolbar which is, by default, at the bottom of the screen).
  • Minimize/Maximize/Close buttons are to the left instead of to the right.
  • Maximize button only maximizes to the required extent instead of occupying the entire desktop.
  • Important keyboard shortcuts
    • F9 - Shows all open windows
    • F10 - Shows all open windows for the current application (every thing else is greyed out)
    • F11 - Hides all windows and shows the Desktop
    • F12 - Show Dashboard

Here are some other tasks that I tried:

  • iMovie is really cool, I could easily create a movie (with in-built camera) and upload a video directly to youtube. Really good intuitive interface.
  • Create clean HTML pages (like this blog): TextEdit (the default editor) adds redundant markers and viewing HTML source code is not intuitive/easy. So does NeoOffice. Microsoft Front Page is really good at that and I've thoroughly enjoyed editing my blogs using it. So I'm looking for something comparable on Mac. I found this HTML editor shootout  but most of the editors seem to require some manual addition of HTML tags. Googling further, I found KompoZer (based on Nvu) and liking it so far. Part of the reason is that the look-and-feel is quite like FrontPage ;-)

These tips will at least get you started where you can check Email, IM and Web, view your documents, import key settings from Firefox/Thunderbird and unleash the potential of GlassFish and NetBeans. Lots of other tips are available here, here and here. I'll post more as I learn them. Feel free to post your favorite tool/tip/guidance here.

A complete archive will be available here.

Technorati: windows mac apple tools osxtips

Thursday Nov 08, 2007

JRuby 1.0.2 released - Improved Windows experience and Rails 1.2.5 support

JRuby 1.0.2 was released last week.

A total of 99 issues were fixed but I'm particularly excited about JRUBY-1347, JRUBY-1350, JRUBY-1401 and JRUBY-1410. These are some issues that I faced (1347 here, 1350 here, 1401 here, 1410 here) on my primary development machine - Windows.

Here is the status report:

  • On Windows only, the latest Rails gem (1.2.5) is now working with stable release of JRuby (1.0.2 as of today).

  • On Windows only, GlassFish v3 gem does not work with JRuby 1.0.2 but works with the JRuby trunk (JRUBY-1549). The gem works correctly on Solaris and Mac.

  • JRuby 1.0.2 bundles will be available on GlassFish Update Center soon.

Now the details.

Here is the command sequence for creating and hosting a trivial Hello World on WEBrick:

  1. Install Rails

    C:\\testbed\\ruby\\jruby-1.0.2>bin\\jruby -S gem install rails --include-dependencies --no-ri --no-rdoc
    Bulk updating Gem source index for: http://gems.rubyforge.org
    Successfully installed rails-1.2.5
    Successfully installed activesupport-1.4.4
    Successfully installed activerecord-1.15.5
    Successfully installed actionpack-1.13.5
    Successfully installed actionmailer-1.3.5
    Successfully installed actionwebservice-1.2.5

  2. Create a template application

    C:\\workarea\\samples\\rails>\\testbed\\ruby\\jruby-1.0.2\\bin\\jruby -S rails hello
     create
    create app/controllers
    create app/helpers
    create app/models
    create app/views/layouts
    create config/environments
    create components
    create db
    create doc
    create lib
    create lib/tasks
    create log
    create public/images
    create public/javascripts
    create public/stylesheets
    create script/performance
    create script/process
    create test/fixtures
    create test/functional
    create test/integration
    create test/mocks/development
    create test/mocks/test
    create test/unit
    create vendor
    create vendor/plugins
    create tmp/sessions
    create tmp/sockets
    create tmp/cache
    create tmp/pids
    create Rakefile
    create README
    create app/controllers/application.rb
    create app/helpers/application_helper.rb
    create test/test_helper.rb
    create config/database.yml
    create config/routes.rb
    create public/.htaccess
    create config/boot.rb
    create config/environment.rb
    create config/environments/production.rb
    create config/environments/development.rb
    create config/environments/test.rb
    create script/about
    create script/breakpointer
    create script/console
    create script/destroy
    create script/generate
    create script/performance/benchmarker
    create script/performance/profiler
    create script/process/reaper
    create script/process/spawner
    create script/process/inspector
    create script/runner
    create script/server
    create script/plugin
    create public/dispatch.rb
    create public/dispatch.cgi
    create public/dispatch.fcgi
    create public/404.html
    create public/500.html
    create public/index.html
    create public/favicon.ico
    create public/robots.txt
    create public/images/rails.png
    create public/javascripts/prototype.js
    create public/javascripts/effects.js
    create public/javascripts/dragdrop.js
    create public/javascripts/controls.js
    create public/javascripts/application.js
    create doc/README_FOR_APP
    create log/server.log
    create log/production.log
    create log/development.log
    create log/test.log

  3. Add a controller

    C:\\workarea\\samples\\rails>cd hello

    C:\\workarea\\samples\\rails\\hello>\\testbed\\ruby\\jruby-1.0.2\\bin\\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

  4. Edit Controller

    C:\\workarea\\samples\\rails\\hello>vim app\\controllers\\say_controller.rb

    Add  @hello_string = "Hello from 1.0.2" in hello helper. The updated file looks like:

    class SayController < ApplicationController

      def hello
        @hello_string = "Hello from 1.0.2"
      end
    end

  5. Edit View

    C:\\workarea\\samples\\rails\\hello>vim app\\views\\say\\hello.rhtml

    and add <%= @hello_string %> as the last line. The updated file looks like:

    <h1>Say#hello</h1>
    <p>Find me in app/views/say/hello.rhtml</p>
    <%= @hello_string %>

  6. Start WEBrick and view the page http://localhost:3000/say/hello in a browser window:

    C:\\workarea\\samples\\rails\\hello>\\testbed\\ruby\\jruby-1.0.2\\bin\\jruby script\\server
    => Booting WEBrick...
    => Rails application started on http://0.0.0.0:3000
    => Ctrl-C to shutdown server; call with --help for options
    [2007-11-07 17:22:01] INFO WEBrick 1.3.1
    [2007-11-07 17:22:01] INFO ruby 1.8.5 (2007-11-01) [java]
    [2007-11-07 17:22:01] INFO WEBrick::HTTPServer#start: pid=11245030 port=3000
    127.0.0.1 - - [07/Nov/2007:17:22:38 PST] "GET /say/hello HTTP/1.1" 200 81
    - -> /say/hello

The GlassFish v3 Gem does not work with JRuby 1.0.2 (JRUBY-1549) on Windows. It works very well on Solaris and Mac. For Windows, you need to use the JRuby trunk (checkout and build):

After you've built the JRuby trunk, you can create a similar new application and run it on GlassFish v3 gem as:

  1. Download and Install the gem

    C:\\workspaces\\jruby-trunk>bin\\jruby -S gem install glassfish-gem-10.0-SNAPSHOT.gem
    Successfully installed GlassFish, version 10.0.0

  2. Start GlassFish v3 and view the page http://localhost:8080/hello/say/hello:

    C:\\workarea\\samples\\rails>\\workspaces\\jruby-trunk\\bin\\jruby -S glassfish_rails hello
    Nov 8, 2007 2:39:07 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter postConstruct
    INFO: Listening on port 8080
    Nov 8, 2007 2:39:08 PM com.sun.enterprise.v3.services.impl.DeploymentService postConstruct
    INFO: Supported containers : php,phobos,jruby,web
    Nov 8, 2007 2:39:08 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init>
    INFO: New Servicing page from: C:\\workarea\\samples\\rails\\hello\\public
    Nov 8, 2007 2:39:15 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 7588 ms
    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO:

    Processing SayController#hello (for 127.0.0.1 at 2007-11-08 14:39:27) [GET]

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Session ID: 46e3279ab4f2d776b4d76010cc7b38af

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Parameters: {"action"=>"hello", "controller"=>"say"}

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Rendering say/hello

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Completed in 0.01100 (90 reqs/sec) | Rendering: 0.00900 (81%) | 200 OK [http://localhost/hello/say/hello]

A comprehensive list of JRuby on GlassFish documentation is available here.

Technorati: jrubyonglassfish jruby glassfish windows rubyonrails v3 gem ruby

Tuesday Oct 16, 2007

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

About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

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