Spiritual java is an attempt to let me express my thoughts, my ideas, my views and my feelings about two topics which are very close to my heart. Vippasana and Java!!! I have been practicing Vipassana for more than 8 years now and in all these years the way this teqnuqie helped me in overcoming many ups and downs in my life is quite remarkable. Java on the other hand is my source of my materialistic existence. So I'll be sharing my views on J2EE technology and its relevance in web.

Tuesday 29 September 2009

Installing tomcat in Mac OSX leopard

Found an interesting link for installing Tomcat on Mac OSx. Hope you will find it useful. This post gives details instructions to install the tomcat. Have a look at it.
http://www.malisphoto.com/tips/tomcatonosx.html

Saturday 26 September 2009

Creating HelloWorld webapp in Lift and Deploying it on Tomcat 6.x

In this post I'm going to create a very simple webapp on lift and then deploy it on tomcat 6. As usual, I'm going to use mac OsX but it should not be too different on any other environment. The most funny part is that we don't have to write a single line of code to make our Helloworld app! A sample HelloWorld app for lift framework already comes in as Maven build.


So lets get started, first u need to have the following:
  • jdk 1.5 or above installed on ur system. You can download it from here.
  • Latest Maven  installation. You can download it from here.
  • Scala Plugin for eclipse. See how to install it from here.
Once everything is installed go to the command prompt and check mvn version.


suresh-sharmas-macbook-pro:~ sureshsharma$ mvn -version


Maven version: 2.0.9
Java version: 1.5.0_19
OS name: "mac os x" version: "10.5.8" arch: "i386" Family: "unix"
suresh-sharmas-macbook-pro:~ sureshsharma$


This should tell u the maven version installed. Now go to ur workspace directory, in my case it is /Projects


At the command prompt give the following command; I'll explain the
meaning of it a little later.


Suppose I want to create a project called helloworld and want to be
packaged under com.elslon.lancet.rad, then first I'll go to my
workspace /Projects


suresh-sharmas-macbook-pro:~ sureshsharma$ mvn archetype:generate -U \-DarchetypeGroupId=net.liftweb \-DarchetypeArtifactId=lift-archetype-blank \-DarchetypeVersion=1.0 \-DgroupId=com.elslon.lancet.rad \-DartifactId=helloworld \-Dversion=1.0-SNAPSHOT


Once executed it will dispaly a list of outputs in verbose mode. At one or two places you may be prompted, just press enter.


Once it is done and u get back to the command prompt u are ready to  launch your first app. Go to the project directory.


suresh-sharmas-macbook-pro:Projects sureshsharma$ cd helloworld


suresh-sharmas-macbook-pro:helloworld sureshsharma$ ls
pom.xml src
suresh-sharmas-macbook-pro:helloworld sureshsharma$


Maven. Comes in with inbuilt jetty and tomcat plugin so give the following command for tomcat deploy the app using tomcat plugin for maven.


suresh-sharmas-macbook-pro:helloworld sureshsharma$ mvn tomcat:run


And here u go it will start tomcat plugin and u will be able to see it running at http://localhost:8080/


The next step is to create a war file to be deployed on tomcat, go to  helloworld directory, you should see that pom.xml and target directory present there. Give the following command mvn package. This is maven's task that builds and creates the war file and place it in target directory. In our case the war file will be created in /Projects/helloworld/target/helloworld-1.0-SNAPSHOT.war.


Now take the war file and deploy it on tomcat. Start the tomcat and here you go! You have deployed your helloworld lift webapp on tomcat.


Sunday 13 September 2009

Creating Simple Hello World webapp in JRuby on Rails

In this post I'm going to create a simple Hello World webapp on JRuby on rails right from the scratch.

I'm using Mac OSX version 10.5 for development  but I assume it would not be very different on other OS like Windows.
I like to do all the installation in directory /usr/local.  You can go to this directory from the terminal or from finder. Just keep in mind that this location is not visible from the finder window as the folder /usr is hidden by default. Click here to see how to open this window in finder.

First we need to install the latest version of JRuby. The zip file can be downloaded from here.
Once downloaded extract and move the jRuby folder to /usr/local

>mv /Users/sureshsharma/Downloads/jruby-1.3.1 /usr/local/jrub

After that go to the ~/.profile file and update the path for the installation
export PATH=/usr/local/jruby/bin:/usr/local/bin:/usr/sbin:$PATH

Now install rails, mongrel and jdbc adapter.If you are using sqlite3 instead of mysql then you must install the jdbc-sqlite3 adapter.
>sudo /usr/local/jruby/bin/gem install rails mongrel activerecord-jdbcsqlite3-adapter rspec rack rake jruby-openssl activesupport
At this point you have the following things installed.
  • JRuby
  • Rails framework
  • mongrel server
  • jdbc sqlite3 adapter
Now we are ready to go and create our hello world app. 
Create a workspace directory to create the jruby project. In my case it is /Projects. 
Once inside give the following command 
/Projects>jruby -S rails helloWorldPrj
This command will create a project helloWorldPrj inside /Projects folder. 
Ok now lets create a controller.
/Projects/helloWorldPrj>jruby -S script/generate controller home

The above command will create the following for you:

  • A controller called HomeController in /helloWorldPrj/app/controllers/home_controller.rb
  • A view Helper called HomeHelper in /helloWorldPrj/app/helpers/home_helper.rb
  • a view folder in /helloWorldPrj/app/views/home
Now open your favorite editor to proceed. In my case I'm using Rad-Rails editor plugin for Eclipse. Go to the install and update new softwares option and give the following url http://update.aptana.com/install/rails/
Make sure you install only the RadRails editor infrastructure and nothing more than that. We will add on the stuff as and when we need it.
Once it is installed change to RadRails perspective and in the Ruby explorer 
right click->new Project->Rails Project
Yes, you need to create new Rails Project even though we are going to use our existing helloWorldPrj project.
In the New project window uncheck both the following two options
  • Generate Rails Application skeleton
  • Automatically start server after project is created
Type in the name helloWorldPrj in the project name and press ok. This will automatically import the existing project that we created from the terminal into the Ruby explorer.
Open /helloWorldPrj/app/controllers/home_controller.rb file and create an action called view

class HomeController < ApplicationController
  def view
   @model = "Hello world!!!"
  end
end

Next go inside the /helloWorldPrj/app/views/home folder and create a view.html.erb file. This will be our view template.
Inside the body tag give the following 



<body>This is my first  application!!!
body>

Now the next most important thing; because we are using sqlite3, go to /helloWorldPrj/config/database.yml and change the development,test and production adapters to jdbcsqlite3 
/helloWorldPrj/config/database.yml file should look like this
# SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: jdbcsqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: jdbcsqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000
production:
  adapter: jdbcsqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
We are done now!!! Go inside the titi project and start the server
/Projects/helloWorldPrj>jruby -S script/server
Now go the browser and check this out at  http://0.0.0.0:3000/
You should see something like this

Now check out your hello world page at http://0.0.0.0:3000/home/view
Congratulations!!! You have just created your first Hello world jruby web application :-)

How to find hidden folders in finder on Mac OS X

Go to the finder and on the menu bar select Go->Go to Folder (or use shortcut key cmd+shift+G) 
After that a window will open as shown below. Type in any path you want to go; say for instance you want to go to hidden folder /usr/local, just type in that. It will open the folder in finder.

How to take screen snapshot in Mac OS X

Taking screen snapshot in Mac OS X is very simple. If you want to capture the snapshot of the entire screen just press cmd+shift+3 and you will hear a camera click sound!!! Go to the desktop and you will see by default an image called picture-1 is created there. Thats all :-)

If you want to take the snapshot of only a selected area of the window then press cmd+shift+4 and this time you will see that your mouse pointer has become an area selection pointer. Select the area of the window you want to take the snapshot and release the mouse pointer, again you will hear a camera click sound !!!. Go to the desktop and find your image there. Dead simple on Mac... making simple things simpler... thats Mac for you :-)

Thursday 10 September 2009

Unique way to tackle ATM Thefts

I'm deviating from my normal post and want to share an information about an interesting mail that i received recently. Not too sure whether it is correct or not as I never dared to try it and hope nobody need to try it either!!!
Say for instance you are in an ATM and you see a man just behind you and that he is too close to you for your comfort.

You look back and he stares at you, reaches his pocket and takes out a gun, soon his accomplice follows

Now what do you do? Do you fight back or try to run? or try to raise an alarm?....
The answer is no.... don't do that... read the following excepts from mail carefully!!!

"... WHEN A THIEF FORCES YOU TO TAKE MONEY FROM THE ATM, DO NOT ARGUE OR RESIST,
YOU MIGHT NOT KNOW WHAT HE OR SHE MIGHT DO TO YOU.   WHAT YOU SHOULD DO IS TO

PUNCH YOUR PIN IN THE REVERSE, I...E IF YOUR PIN IS 1254, YOU PUNCH 4521.  


THE MOMENT YOU PUNCH IN THE REVERSE, THE MONEY WILL COME OUT BUT WILL BE

STUCK INTO THE MACHINE HALF WAY OUT AND IT WILL ALERT THE POLICE WITHOUT THE NOTICE OF THE THIEF.
EVERY ATM HAS IT; IT IS SPECIALLY MADE TO SIGNIFY DANGER AND HELP. NOT
EVERYONE IS AWARE OF THIS.
..."


Please share this post with your friends, relatives and colleagues of yours.

Saturday 5 September 2009

A quick intro to Mercurial Revision control system

This post is for all the developers who are using revision control systems like CVS to use Mercurial. This post just contains a few brief descriptions and urls from where more information can be found about using the mercurial

Ok so lets get started.

Few FAQ which will make you familiar with the terminologies used in mercurial.


What is tortoiseHg?
This is a windows version of Mercurial. It is like tortoise for CVS.
Ok fine, but then what is Mercurial?
It is a revision control system just like CVS
And what is Hg?
Its the chemistry name of Mercurial :-)

Something to know for developers who are on Mac 
What is Ticke(TCL)?
Tools command language is a scripting command language like ruby
What is macport(s)?
Macport is a command line package distribution tool just like ruby gem for Mac.
From where can I install mercurial on my machine?
For windows: download the latest version from http://bitbucket.org/tortoisehg/stable/wiki/Home

For Mac OS-X: Install it from http://mercurial.berkwood.com/
Ok, how can i get started with mercurial once i have installed it?
Installing mercurial is just like creating any new directory in your machine which contains all the version control information.
To create a hg repository
hg init myproject

This will create a new repository call myproject
Go inside this and copy any file you want to provide versioning with.
To add the file to the repository
hg add
This will add the copied file to the repository
To check the status of the added file
hg status
To commit changes
hg commit -m 'initial commit'

Detailed instructions can be found at the link below