Sunday, May 8, 2011

Learning Scala - Code Update without Redeployment via JRebel

Scala Developer entitles to free license from JRebel, just request it from ZeroTurnaround (http://sales.zeroturnaround.com/), the license will be emailed to you in minutes. You'll need to download and install JRebel as well.

Having done so, you are only 2 steps away from code update without redeployment.

Step 1
Changed your sbt launch script, I have changed mine to:-


#!/bin/sh
java -Xmx1512M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -noverify -javaagent:/opt/ZeroTurnaround/JRebel/jrebel.jar -jar /opt/sbt/sbt-launch-0.7.5.jar "$@"


Note that I installed my sbt jar in /opt/sbt/ and JRebel in /opt/ZeroTurnaround/JRebel/.

Step 2
Change your Web Project build class:-


import sbt._
class WebAppBuild(info: ProjectInfo) extends DefaultWebProject(info) {

val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test"
val servletApi = "javax.servlet" % "servlet-api" % "2.5"

override def jettyWebappPath = webappPath
override def scanDirectories = Nil
}


That's all for the setup, now you can launch sbt in your project directory and test:-


jetty-run
~ prepare-webapp


Go ahead and change your Servlet source file, upon saving, you can refresh your web browser to see your changes immediately, without the need to redeploy the whole web app.

Learning Scala - Continuous Redeployment with jetty-run

To make jetty-run to auto-detect and redeploy the web app, run the following commands in sbt:-


jetty-run
~ prepare-webapp


Now you can change your servlet source code and save, the web app should get compiled and redeployed automatcally.

Saturday, May 7, 2011

Learning Scala : Hello World Web App with SBT

Creating Project:-


mkdir HelloWorld
cd HelloWorld
sbt


You will be prompted to create new project, type 'y' and enter project name, organization, version etc.:-


Name: HelloWorld
Organization: QQ Enterprise
Version [1.0]:
Scala version [2.8.1]:
sbt version [0.7.5]:


Required Scala libraries will be downloaded automatically, make sure you are connected to internet.

Create WebAppBuild.scala build in project/build/ (create build directory if it's not there):-


import sbt._
class WebAppBuild(info: ProjectInfo) extends DefaultWebProject(info) {
val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test"
val servletApi = "javax.servlet" % "servlet-api" % "2.5"
}


In the SBT console, enter:-


reload
update


Create HelloWorldServlet.scala in src/main/scala directory:-


import javax.servlet.http._
class HelloWorldServlet extends HttpServlet {
override def doGet(req: HttpServletRequest, resp: HttpServletResponse) = {
resp.getWriter().print("Hello World!")
}
}


Create webapp directory in src/main, and consequently create WEB-INF directory and web.xml:-


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>


In SBT, run:-


reload
jetty-run


Open your web browser and go to http://localhost:8080, you should see the Hello World! message being print out from your simple servlet written in Scala.

Monday, March 28, 2011

Rip Movie from DVD iso to mpg

Using mencoder:-

mencoder input.iso -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video -oac mp3lame -aid 0 -o output.mpg

Wednesday, November 3, 2010

Get Domain Class's Error Message in Grails Controller

The following code snippet can be used to get domain class's error messages in Grails (1.2.2) Controller:-


def errMsgList = domainClassObj.errors.allErrors.collect{g.message([error : it])}

Reset Netbeans JDK Home

I always need to reset Netbeans JDK Home whenever I install new JDK version, this serves as my own note to remember:-

To reset, change 'netbeans_jdkhome' entry in {NETBEANS_INSTALL_FOLDER}/etc/netbeans.conf.

Sunday, September 5, 2010

Integrating BlazeDS to Grails

Sebastien has written a very good Grails plugin for using BlazeDS in Grails project:-

Grails BlazeDS 4 Integration Plugin

Grails/BlazeDS/Flex/iPhone Full Stack Part1/3

Grails/BlazeDS/Flex/iPhone Full Stack Part 2/3

If you are like me, who try to integrate BlazeDS by hand (by downloading BlazeDS separately and putting in jars and configuration files into existing Grails project), you must use 'run-war' instead of 'run-app' to run your project or you might get 'Type xxxxx not found' error when invoking a BlazeDS service. I solved this after reading notes in Sebastien's blog:-

Run your Grails application using “grails run-war” instead of “grails run-app”. Once again this is a known limitation: Flash Builder BlazeDS data connection plugin relies on a classical web app layout and doesn’t understand Grails dynamic layout (that is until someone manages to create a Grails data connection wizard for Flash Builder 4)