Wednesday, January 15, 2014

How to deploy a web application outside Tomcat and use JRebel to prevent restarts to see the code changes

There are 2 things I feel are slowing me down while building java applications. And 1st one is copying the web applications into webapps folder of the Tomcat.After I make changes to the java code I have to compile the code, make the war file and deploy it in the webapps folder of Tomcat. This slows down the development process and java developers just wish they can avoid this. There are couple of ways to avoid this.

Deploying web application outside the Tomcat WebApps folder

One of the way is to deploy the war outside the webapp of the Tomcat which is described below.

Move to the following location in your Tomcat installation folder.

<Tomcat Home>--> conf --> Catalina --> localhost

In this folder create a xml with the name of your web application.Say I want my service to be 'MyApp1' then create a 'MyApp1.xml' in the above path.

Add the below content in the file created.

<Context path="/MyApp1" docBase="C:\Users\vkiran\Desktop\MyApp1\war" reloadable="true">

Your are defining the  context name for your application and providing a location which has your compiled web application for the Tomcat to load. When you start the Tomcat, Tomcat will load your web application 'MyApp1' from  'C:\Users\vkiran\Desktop\MyApp1\war' location. So you don't need to copy your war file to Tomcat webapp folder every time.


But you still need to compile your code and restart Tomcat for every code change you make.Redeploying the application for every small change in the code is one of things I hate  most in Java. JRebel provides a relief from this constant recompiling mess. JRebel reloads the classes without redeploying the application and so you can view your code changes without restarting the applications.It supports most of the Java Frameworks, has plugins for all major java IDE's and is a great productivity tool for java developers. It is a paid tool and a trial version can be downloaded from here.

Download and extract the zip file.

In Tomcat --> bin folder, create a 'catalina-jrebel.bat' file with the following content.

@echo off
set JAVA_OPTS=-javaagent:[path/to/]jrebel.jar %JAVA_OPTS%
call "%~dp0\catalina.bat" %*

The jrebel.jar is available in the extracted zip file. Replace '[path/to/]' in the above script with the path to the jrebel folder on your system.

If you want to launch your Tomcat with JRebel enabled, run this catalina-jrebel.bat.

catalina-jrebel.bat run

If you configured jrebel correctly on Tomcat, you will see some thing similar on your command prompt when you start the Tomcat. Some information on where the jrebel log file goes, what is the version, statistics on the time saved using jrebel and license etc.

Also the command prompt will display the list of frameworks supported by jrebel but not used/enabled in your application and if there are any updates to jRebel.

If Tomcat is run as a service in your development environment, select 'Monitor Tomcat' from your Run --> Programs or double click on the Tomcat icon in the system tray. Then insert the below parameter in Java --> Java Options


Replace [path/to/] with the path to the jrebel folder on your system.

If you launch the Tomcat with JRebel on, you need not restart Tomcat to see your code changes. Just refresh your browser or test the functionality without restarting the application. JRebel reloads the modified classes and so you can concentrate on your code changes without getting distracted by the continuous re-deployments.

Monday, January 13, 2014

Using Ripple to emulate Apache Cordova / Phonegap applications.

Apache Ripple

After somegap I had to use Ripple emulator when I was trying to upgrade GWTPhonegap to support Apache Cordova 3.3. Apache Ripple is a browser agnostic mobile emulator. This will enable rapid development of Hybrid mobile applications using frameworks like Apache Cordova and Blackberry webworks. Ripple was initially developed by Blackberry and then donated to Apache open source community. Similar to Apache Cordova, Apache Ripple is a free and Open sourced under the Apache License, Version 2.0


The latest version of Ripple is distributed using nodejs and so you need to install nodejs first. The instructions to install nodejs are available here.

After installing nodejs, open the command prompt/terminal and run the below command to install ripple emulator.

npm install -g ripple-emulator

And since you will be emulating Apache Cordova applications, you need to install Cordova and create a Apache Cordova application.The instructions to install Apache Cordova are available here.

Running Ripple

Once you create a Apache Cordova project, make changes to the code, add the platform, prepare the project running the below command.

cordova prepare

The above command needs to be run every time you make changes to your project.

Run the below command from the root of your project to start the Ripple emulator.

ripple emulate

Once you run the above command, ripple will launch the default browser on the system. Your application will be emulated in the browser launched.

Some times you may see the below error page after Ripple launches the browser.

Just click on 'Wait' button or refresh to resolve the error.


The devices section highlighted below provides options to emulate the application on different devices.

There is a option to select the device which we need to emulate. There are several Blackberry, Android and iOS devices available which can be emulated.

Also there is an option to simulate the vertical and horizontal orientation also.Just click on the vertical or horizontal  icon against Orientation label to simulate Vertical or Horizontal orientation.


The platform section provides options to choose the platform and version to be used for emulation.

The platform drop-down provides options to select a platform among WebWorks, Phonegap to emulate.

You can also select the version you want to emulate.Apache Cordova provides versions 1, 2 & 3. I believe all the versions between 1 and  2 can select 1 and so on.


The information section provides information about the environment that is being emulated.The description of  the information displayed is below.

Version: version of the application
Platform: The framework that is being emulated.
Device: The device that is being emulated.
OS: Operating system of emulated device.
Manufacturer: Manufacturer of the device that is being emulated.
Screen: The screen resolution of the emulated device.
Density: The pixel density in the app you are emulating.
CSS Pixel Ratio: The device pixel ratio is the ratio between logical pixels and physical pixels.This indicates the pixel ratio of the emulated device.
CSS Pixels:The CSS pixels that is being emulated.
User Agent: Indicates the user agent in device that is being emulated.


The accelerometer allows us to emulate the device motion changes using accelerometer  framework. You might as well emulate shaking the device to test the device motion changes. You can use the device icon in this section to emulate the device motion actions.


The 'Settings' has options to switch the themes between 'Light' or 'Dark' and you can turn the tool tips on or off.

Desktop browsers have a limitation which restricts the Ajax code from making cross domain requests. This is a security restriction on all the browsers. Chrome provides an flag to bypass that restriction. 

The Cross Domain Proxy is one of most useful features of the Ripple emulator. Ripple proxies the request made from then application, makes a request for the data from its own server and then proxies the result back to the application.

Device & Network Settings

This section provides you an option to emulate the network and gloabalization API of the Cordova framework.

You can select the connection type you want to select from all the connection types like ETHERNET, Wi-Fi, 2G, 3G, 4G and also you can indicate if there is a network lag or not.

There are also some functions from globalization API which can be emulated. You can provide the locale name, whether the day light savings are enabled or not and also the first day of the week. The values provided here will be used by your application when these functions are called.

Geo Location

The geolocation allows you to emulate the location related API in your application. You can enter the values to mock in the geolocation section and they will be used by your application.


The Ripple emulator reads the configuration file and displays the result in this section . If there are any errors or issues they will be displayed here.


The Events section provides several events(device ready, back button,pause, resume, search button, menu button, offline, online) which are supported by Apache Cordova. While these events are not actually simulated, they are just registered. Say if you select back button, the event will be registered to the Cordova API, but it doesn't simulate the actual hardware event.


Ripple supports some of the functions related to Camera API also. It allows you to select a image from your system and then use it for mocking the functionality later.

Unsupported options

As you can see by now, Ripple doesn't support all the options provided by Apache Cordova. When Ripple encounters a call that it doesn't support, it shows up a pop up similar to below.

In this case you can enter the JSON object to the callback that you want to execute.


Ripple is an excellent development tool to emulate the Apache Cordova applications on desktops. You will be able to switch between different OS's like Android, i-OS and Blackberry. And you will able to get a first hand feel of how your application looks on different devices and also in horizontal and Vertical orientations. There may be some limitations in Ripple, but I believe it is a must use tool for developers developing cross platform mobile applications using Apache Cordova. And once you are done with developing, you need make sure you will test the application on real device before pushing the applications to App Stores.

Friday, January 10, 2014

Installing Nodejs


Nodejs is a platform for building fast and scalable network applications. Apart from building applications, it is used for distributing several tools, frameworks like Apache Cordova, Apache Ripple.


The installation of nodejs is straight forward. nodejs can be downloaded from the below URL.

Click on the 'INSTALL' button to download the installer.

The downloaded file will be like 'node-v0.10.24-x86.msi'. The file name may vary a little bit based on the version downloaded and the OS version architecture.

Double click on the installer to start installation.

Click on 'Next' in the welcome screen.

Accept the license agreement and click on 'Next'.

Select the installation location and click on 'Next'.

Normally you need to install all the packages and so click on 'Next' without making changes. If you are sure you dont need some of the components like 'Online documentation shortcuts' deselect it and click on 'Next'.

The installer will start installing the nodejs on your system. Just wait for few seconds to allow the installation to complete.

Click on 'Finish' to complete the installation.

To check the installation, open command prompt and check the version by typing the below commands.

node -v
npm -v

node -v should display the version of the nodejs you have downloaded and installed.