Technologies

I will mostly write about following

Java, J2EE, GWT(Google Web Toolkit), HTML, Javascript, Linux, MacOS, Queue, Docker, Cloud hosting, Auto Scaling, Web, Ad Serving etc.

Remove cookie.

To remove cookie from server one need to set its expiry time to current time. e.g. J2EE container one can remove the cookie in following way HttpServletResponse response = (HttpServletResponse) servletResponse; Cookie cookie = new Cookie("cookie-key", ""); //.... set all the other attributes same as that of existing cookie, like path and domain. cookie.setMaxAge(0); response.addCookie(cookie); setting max age of cookie to 0 I am setting its expiry to current machine time. [Read More]

Quick enable simple password protected Remote JMX with tomcat

You need to do following configuration to enable Remote JMX monitoring on tomcat server. Copy jmxremote.password.template located at JRE_HOME/lib/management inside the same folder with the name jmxremote.password. Edit this jmxremote.password file, uncomment last two lines starts with monitorRole and controleRole, instead of QED and R&D set some good password for both of them. Change directory to CATALINA_HOME/bin from where you start the tomcat. You will find setenv.sh (if you don’t find it create one) and add following line inside file CATALINA_OPTS="$CATALINA_OPTS -Dcom. [Read More]
JMX 

apiary.io sample

First of all I must mention apiary.io has done great job by providing some easy means to have REST api documentation, collaborate as well as expose it to public or keep it private. With the new release of the same I was struggling little bit to make use of the new version, for that I had to go through the detailed documentation (refer). But I felt this tutorial just demonstrates blueprint code, it doesn’t show the corresponding preview related to given blueprint code. [Read More]

Convert mercurial (hg) to git repository for bitbucket

To convert hg repository on bitbucket to git repository follow below steps. Create new repository with Repository Type selected as Git follow below commands with the assumption that you already have hg repository cloned on your system. If not then you first need to clone existing hg repository. Steps to follow $ git clone git://repo.or.cz/fast-export.git $ mkdir <new git repo> $ cd <new git repo> $ git init $ ../fast-export/hg-fast-export.sh -r <path to hg local repository> $ git checkout HEAD $ git remote add origin https://<username>@bitbucket. [Read More]

Install and run memcached on OS-X

One need to have gcc installed for that you need to install xcode along with command line tools. To install the same one can refer to this link for xcode 5.0.1. Libevent is required to be installed for memcached, if it is already installed on your machine you can skip this step. Create temp directory and change directory to that location and execute following commands. $ curl -O http://www.monkey.org/~provos/libevent-1.4.14-stable.tar.gz $ tar xzvf libevent-1. [Read More]

Access file (JAVA)

Access resource / file packaged inside a jar or a located on classpath. Two ways to access the file located inside jar or located on classpath. Use getResourceAsStream("filename") on ClassLoader, one can retrieve the class loader instance from class instance of any class or Thread.currentThread().getClassLoader(). When you try to load the file using class loader, file will be always searched inside root folder on classpath. e.g. Thread.currentThread().getClassLoader().getResourceAsStream("config.properties") and Thread.currentThread().getClassLoader().getResourceAsStream("/config.properties") either way class loader will try to search file from root folder which is on class path or from root folder inside jar. [Read More]

maven properties not being substituted inside resources

You need to add following configuration which indicates those resources need to be processed and property values will be replaced. By default Maven resources plug-in will not do property value substitution (filtering), so it will need to be enabled within the <build> section of the pom.xml file. Filtering value true will enable the resources processing and substitute property values. In addition to that one can include/exclude the resources <build> ..... . [Read More]

Zeromq setup on MAC OSX 10.9.3 (mavericks) with Java binding

Steps: With reference to following blogs written by Vivek blog to install zeromq and by Jean blog to install auto tools. I faced few issues ( one of them is following error ./configure: line 15284: 'PKG_CHECK_MODULES') which I tried to address with following steps: Install gcc ( to install gcc you need to install xcode 5 download it from `https://developer.apple.com/xcode/ and install.) Make sure you have java installed. If you want to install JDK 7 refer this http://docs. [Read More]
zeromq  OSX  Mac 

Override JPA persistence unit properties in code with Google Guice

To override properties from persistence.xml through code while using it with Google guice. One can read the properties from different source and add those properties while installing JpaPersistModule. Following is the sample Properties persistenceUnit = new Properties(); persistenceUnit.put("javax.persistence.jdbc.url", "jdbc:mysql://192.168.9.102/MyDB"); persistenceUnit.put("javax.persistence.jdbc.user", "myuser"); persistenceUnit.put("javax.persistence.jdbc.password", "mypassword"); Injector injector = Guice.createInjector(new JpaPersistModule("my-persistence-unit").properties(persistenceUnit)); One can chose to read this configuration from some other file and install JpaPersistModule with those properties. This could be useful to override database url for test and production. [Read More]

Generate complete package (ZIP) of Java (executable jar) application with required dependencies in it using Maven

To generate a zip file, packaging all required dependent libraries and newly generated jar, using maven-assembly-plugin (for more detail on plugin refer). I will demonstrate generation of package using assembly descriptor file. Create a assembly descriptor file which is a xml file (for more details refer and format) as following. Create this file inside your project directory. One can keep this descriptor file any where inside given project directory. I have tried it by keeping this file at location <Project dir>/src/main/assembly/test-app-assembly. [Read More]