Skip to content

Quick way to change system variables windows

Typically we need to append to system path variables while setting up tools in our dev/test env, windows power shell can help you to do this quickly –


E.g below I am appending xmlbeans to system path.

[Environment]::SetEnvironmentVariable( “Path”, $env:Path+”;C:\Users\rsaini\Downloads\xmlbeans-2.6.0\xmlbeans-2.6.0\bin”, [System.EnvironmentVariableTarget]::Machine )



Windows – GetShortPathName

Many times we face problem due to space in windows file or folder path. Windows provide GetShortPathName  api to get short path name from the long name. Sometime we need to quickly find out short name while middle to doing something. We can use windows power shell to find that out quickly. Here is quick code to do that,

1) Create filesystem object

$a = New-Object -ComObject Scripting.FileSystemObject

2)  Get the directory or file object

$f = $a.GetFolder("C:\Program Files\MySQL\MySQL Server 5.1\bin")

3) Print the short path


That’s all you need to do, to get the short path from long path.

Step by step spring mvc app using java config

Spring 3.0 provides option of configuration via java code. With out going into theory or advantages or disadvantages I will get into steps directly.

Step 1 : Create simple web  application using maven

mvn archetype:generate -DgroupId=org.opencab
    -DartifactId=cabms -DarchetypeArtifactId=maven-archetype-webapp

Step 2: Convert solution to eclipse project

mvn eclipse:clean eclipse:eclipse -DdownloadSources=true
    -DdownloadJavadocs=true -Dwtpversion=2.0

Step 3: Create directory structure under src\main\java folder. rest is created by maven.

── pom.xml
── src
├── main
│   ├── java
│   │   └── org
│   │       └── opencab
│   │           ├── config
│   │           │   ├──
│   │           │   └──
│   │           └── controller
│   │               └──
│   ├── resources
│   │   └──
│   └── webapp
│       ├── index.jsp
│       └── WEB-INF
│           └── web.xml
└── test

Step 4: Modify pom.xml

<project xmlns="" xmlns:xsi=""
<name>cabms Maven Webapp</name>



<!-- Servlet -->


Step 5 : Implement WebApplicationInitializer in your class and override onStartup method.

package org.opencab.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.servlet.DispatcherServlet;

public class Initializer implements WebApplicationInitializer {

public void onStartup(ServletContext servletContext)
throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
servletContext.addListener(new ContextLoaderListener(ctx));


Dynamic servlet = servletContext.addServlet("dispatcher",
new DispatcherServlet(ctx));



Step 6 : Write webconfig

package org.opencab.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

@ComponentScan(basePackages = "org.opencab")
@PropertySource({ "" })
public class WebAppConfig {
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
return resolver;

Step 7 : Write simple hello controller

package org.opencab.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

public class HelloController {

@RequestMapping(value = "/")
public String home() {
System.out.println("HomeController: Passing through...");
return "home";

That’s all you need to bring up simple application using spring javaConfig.
Note that web.xml file will to empty, since all the configuration are moved into java classes.
Full source code is available at

How to change Perl @INC variable permanently.

Recently I worked on legacy Perl application. The target OS was Solaris 10. I needed a  specific version of Perl to make this application work.

I had very restricted permission on this system. I could not install of make any kind of changes on this system. So I copied the Perl libraries local to machine from some other server. But It did not work as Perl was build on other server. So when I was trying to run my application Perl was looking for some path when it was build.

I did some search on internet and first thing I found was this link

But it did not help me at all. I went to next link

what i got from this –

@INC is defined when Perl is compiled and it is embedded in the binary code. You cannot change that, unless you recompile Perl. Not something we would do every day.

Finally stack overflow came to rescue – the following link describe how @INC is constructed.

specifically I was able to change @INC which was encoded into binary just using simple

no lib <'path'>

We also need to add new path using export PERL5LIB env variable.

Hope this helps you sometime when you don’t have option to compile and other restriction on system where you are working.

Error while installing rails

I was getting my hands dirty with ruby on rails as part of Software as a Service course by Berkeley university. After installing RubyGems next I needed to install rails framework, but I got following error

I am working on ubuntu 12.10 64 bit

sudo gem install rails
Building native extensions.  This could take a while…
ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’: cannot load such file — mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from extconf.rb:1:in `<main>’

Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.7.5 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.7.5/ext/json/ext/generator/gem_make.out

It was referring some package from the ruby1.9.1-dev So I went ahead and installed ruby1.9.1-dev with following command

sudo apt-get install ruby1.9.1-dev

that’s it and sudo gem install rails worked like charm

Minimal Java web services sample.

Minimal Java web services sample.

I needed to write small java web service for POC, I normally start step by step using command line keying in source code in vi editor, so that I can even remember the packages and classes in use. Which normally become transparent when we use IDE. I am not undermining IDE in any way they are great and make development real breeze. But while learning new concepts and tools I prefer to start with minimal sample and then build on them later using IDE etc.

Here is minimal java web service Step by step.

1) Write the web service class implementation to keep the sample minimal I am not going to write interface.

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.WebMethod;
public class hello {
public String hello(){
return "hello world...";

2) Publish the Web Service using Jdk endpoint.

public class h {
public static void main(String []args){
hello he = new hello();
Endpoint.publish("http://localhost:8000/", he);

This will start publishing end point on port 8000. You are done for server-side. Now to consume this service we need to generate proxies to communicate with server.

3) Use wsimport utility to generate proxies

wsimport –d <generated source dir> <web service URL>

e.g wsimport -d gen http://localhost:8000/HelloService/hello?wsdl4) Write the client to consume service.

import javax.xml.namespace.QName;
public class helloClient {
public static void main(String args[]) {
try {
HelloService hs = new HelloService(new URL(
new QName("", "helloService"));
Hello h = hs.getHelloPort();
} catch (MalformedURLException e) {

That’s it you are done in few steps. For theory you can refer to lot of documentation on the web.

How to fix your laptop keyborad if keys comes out and not broken

while cleaning up my laptop keyboard one of key came out and I thought of fixing it myself. I came across this video on youtube and with in few minute I fixed my keyboard. Below is link if you face similar issue.