Dependency injection in the Grails Console

If you have a service named MyService with a function named HelloWorld, you can access it via dependency injection by adding

def MyService
def result = MyService.HelloWorld()

But to test in the console you need to do this:

def service = ctx.getBean("MyService")
def result = service.HelloWorld()
Posted in Grails | Comments Off

How to install Gradle on Ubuntu 10.10

Download zip file from http://www.gradle.org/downloads.html and unzip to folder

$ sudo unzip gradle-1.0-milestone-3-all.zip -d /opt/gradle/

Edit PATH in the environment file

$ sudo nano /etc/environment

Add the following to the environment file

PATH="... :$GRADLE_HOME/bin"
GRADLE_HOME="/opt/gradle/gradle-1.0-milestone-3"

Reload environment variables

source /etc/environment

Add symbolic links to the usr/bin folder

$ sudo ln -sf /opt/gradle/gradle-1.0-milestone-3/bin/* /usr/bin/.

Open a new terminal. Test installation

$ gradle -version
------------------------------------------------------------
Gradle 1.0-milestone-3
------------------------------------------------------------

Gradle build time: Monday, 25 April 2011 5:40:11 PM EST
Groovy: 1.7.10
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.6.0_20 (Sun Microsystems Inc. 19.0-b09)
OS: Linux 2.6.35-30-generic-pae i386
Posted in Ubuntu | Comments Off

How to install Redmine with passenger on Ubuntu 10.10

$ sudo apt-get install redmine redmine-mysql subversion
$ sudo ln -s /usr/share/redmine/public /var/www/redmine
$ sudo apt-get install ruby1.8-dev
$ sudo gem install passenger
$ sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module
$ sudo apt-get install build-essential libcurl4-openssl-dev
libssl-dev apache2-prefork-dev libapr1-dev libaprutil1-dev

The Apache 2 module was successfully installed.
Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-
3.0.2/ext/apache2/mod_passenger.so
   PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.2
   PassengerRuby /usr/bin/ruby1.8

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!
Virtual Host
To serve the Rails application, we need to create a virtual host:

sudo nano /etc/apache2/sites-available/testapp
Although already mentioned, one of the exciting things about mod_rails is that you don’t need any special settings in the virtual host configuration.

The contents can be as simple as this:

<>
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /home/demo/public_html/testapp/public
<>
Of course, you can add custom log file locations and other settings but the main thing to understand is the lack of proxy and port settings.

Once done, we can enable the new site:

sudo a2ensite testapp

Posted in Ubuntu | Leave a comment

Useful commands for ubuntu linux

How to transfer files over ssh

$ scp /your/files/* user@server:/place/to/put/file

How to delete non empty folder

$ rm -rf folder_name
Posted in Ubuntu | Leave a comment

How to choose default Java version

Just installing new Java flavours does not change the default Java pointed to by /usr/bin/java. You must explicitly set this:

Open a Terminal window
Run sudo update-java-alternatives -l to see the current configuration and possibilities.
Run sudo update-java-alternatives -s XXXX to set the XXX java version as default. For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun
Run java -version to ensure that the correct version is being called.

You can also use the following command to interactively make the change;

Open a Terminal window
Run sudo update-alternatives –config java
Follow the onscreen prompt

Posted in Grails | Leave a comment

How to install Groovy on ubuntu 10.10

Download zip file from http://groovy.codehaus.org/ and unzip to folder

$ sudo unzip groovy-binary-1.7.6.zip -d /opt/groovy/

Edit PATH in the environment file

$ sudo nano /etc/environment

Add the following to the environment file

PATH="... :$GROOVY_HOME/bin"
GROOVY_HOME="/opt/groovy/groovy-1.7.5"

Reload environment variables

source /etc/environment

Add symbolic links to the usr/bin folder

$ sudo ln -sf /opt/groovy/groovy-1.7.5/bin/* /usr/bin/.

Open a new terminal. Test installation

$ groovy --version
Groovy Version: 1.7.5 JVM: 1.6.0_20
Posted in Ubuntu | Leave a comment

Using spring security core plugin

Install the plugin

$ grails install-plugin spring-security-core

Create domain classes for User Role and UserRole

$ grails s2-quickstart com.yourapp User Role

Create a persistent token domain class for storing remember-me cookie information in the database

$ grails s2-create-persistent-token com.yourapp.PersistentLogin
Posted in Grails | Leave a comment

How to setup Tomcat and Apache via mod_proxy_ajp

This instruction is for an ubuntu server 10.10.

Tomcat6 configuration

Enable the AJP connector in the /etc/tomcat6/server.xml file like this:

Connector port="8009" enableLookups="false"
         redirectPort="8443" protocol="AJP/1.3"

Restart the Tomcat server.

$ sudo /etc/init.d/tomcat6 restart

Apache2 configuration

Enable the proxy and proxy_ajp modules

sudo a2enmod proxy proxy_ajp

Add new virtual host to the sites-available folder

$ sudo nano /etc/apache2/sites-available/yoursite.com

   ServerName localhost
   ErrorLog /var/log/apache2/ajp.error.log
   CustomLog /var/log/apache2/ajp.log combined

     AddDefaultCharset Off
     Order deny,allow
     Allow from all

   ProxyPass / ajp://localhost:8009/
   ProxyPassReverse / ajp://localhost:8009

Enable virtual host site and restart Apache2

$ sudo a2ensite threebaysover.com
$ sudo /etc/init.d/apache2 restart

If you fail to set the ServerName then on an Apache restart you will see the following warning:

apache2: Could not reliably determine the server's
fully qualified domain name, using 127.0.0.1 for ServerName

To stop the warning and set the ServerName, add the following to the apache2.conf:

ServerName demo
Posted in Apache / Tomcat | Leave a comment