Archive

Archive for the ‘Groovy/Grails’ Category

Get time in millisecond in groovy

July 4, 2011 Leave a comment

I found there are 2 ways to get time in millisecond

 def m1 = System.currentTimeMillis()
 println m1

def m2 = new Date()
 println m2.getTime()
 

Installing Groovy-Grails on Ubuntu

February 13, 2011 4 comments

Now a days I am working with Groovy/Grails. This is really awesome language. Installing this in Ubuntu is very easy and this can be done very fast and in easy way. So how I installed Groovy/Grails up and running.

First install openjdk and groovy. Since in ubuntu these 2 packages are already available. So install it via apt-get.

sudo apt-get install openjdk-6-jdk
sudo apt-get install groovy

java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Client VM (build 14.0-b16, mixed mode, sharing)

groovyConsole

Now for installing Grails. We need to install via binary zip file.
Get the latest Binary Zip file and save to some of your location.
Unzip the folder and move to /usr/share/grails/
I just moved grails to /usr/share/ because ubuntu install Groovy at /usr/share/groovy so making the similarity.

Now Set the JAVA_HOME and GRAILS_HOME path for your profile. Since we are installing Grails via zip binary so we need to tell the system that where is Grails and where is JAVA.

Open ~/.profiles file and add these lines at the top.

JAVA_HOME=/usr/lib/jvm/java-6-openjdk
GRAILS_HOME=/usr/share/grails
PATH=$PATH:/usr/share/grails/bin
export JAVA_HOME PATH
export GRAILS_HOME PATH

And logout and login again and do

printenv

This will show you that Grails path is set for our profile.

Now just say

ganu@ganu:/usr/share/grails$ grails
Welcome to Grails 1.3.6 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

Use ‘grails help’ for more info or ‘grails interactive’ to enter interactive mode

DONE !! WOW.

How to check where Groovy-Grails combination is working.

Go to your development Grails folder.

ganu@ganu:~/grails$ grails create-app wpdemo
Welcome to Grails 1.3.6 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

Base Directory: /home/ganu/grails
Resolving dependencies...
Dependencies resolved in 2867ms.
Running script /usr/share/grails/scripts/CreateApp_.groovy
Environment set to development
...........
Executing tomcat-1.3.6 plugin post-install script ...
Plugin tomcat-1.3.6 installed
Plugin provides the following new scripts:
------------------------------------------
grails tomcat
Created Grails Application at /home/ganu/grails/wpdemo
ganu@ganu:~/grails$ cd wpdemo/
ganu@ganu:~/grails/wpdemo$ ll
total 28
-rw-r--r--  1 ganu ganu  178 2011-02-13 03:43 application.properties
drwxr-xr-x 10 ganu ganu 4096 2010-12-15 08:22 grails-app
drwxr-xr-x  2 ganu ganu 4096 2011-02-13 03:43 lib
drwxr-xr-x  2 ganu ganu 4096 2011-02-13 03:43 scripts
drwxr-xr-x  4 ganu ganu 4096 2011-02-13 03:43 src
drwxr-xr-x  4 ganu ganu 4096 2011-02-13 03:43 test
drwxr-xr-x  7 ganu ganu 4096 2010-12-15 08:22 web-app
ganu@ganu:~/grails/wpdemo$ grails run-app
Welcome to Grails 1.3.6 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

Base Directory: /home/ganu/grails/wpdemo
Resolving dependencies...
Dependencies resolved in 2986ms.
Running script /usr/share/grails/scripts/RunApp.groovy
Environment set to development
...........
Running Grails application..
Server running. Browse to http://localhost:8080/wpdemo

Groovy/Grails SEtup

Groovy/Grails SEtup

Happy Programming.

Groovy: Use findAll to fetch string from long string.

December 18, 2010 Leave a comment

How to use findAll() in groovy, when you have to find some specific string from string.

def name= 'this#   is to%% te$st ^in*d~~ all $$from CCa s<>>ng, this is basi?><:"{}cally fetch only interested thing.'
def name1 = ''
def findName = name.findAll(/[A-Za-z\s+]/).each{name1 += "${it}"}
println findName
println name1

We can also use

def findName = name.findAll(/[A-Za-z\s+]/)
def name1 = findName.join('')

This code will fetch only sting and space and give output in name1.

Output -

run-single:
[t, h, i, s,  ,  ,  , i, s,  , t, o,  , t, e, s, t,  , i, n, d,  , a, l, l,  , f, r, o, m,  , C, C, a,  , s, t, i, n, g,  , t, h, i, s,  , i, s,  , b, a, s, i, c, a, l, l, y,  , f, e, t, c, h,  , o, n, l, y,  , i, n, t, e, r, e, s, t, e, d,  , t, h, i, n, g]
this   is to test ind all from CCa sting this is basically fetch only interested thing
BUILD SUCCESSFUL (total time: 1 second)

Program has many ways to do.
Happy Programming.

Follow

Get every new post delivered to your Inbox.