Pages

Saturday, 7 May 2016

How to enable debug in java application?

To enable debugging in java applications add the jvm arguments,

For Java versions < 5.0 use the following Xdebug and Xrunjdwp args,

    -Xdebug

  -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

 The above options will work in version greater than JDK 5.0 but not recommended and will not be faster since it will run in interpreted mode instead of JIT, which will be slower.


For latest version you can use the following and the above jvm arguments to enable debugging,

    it is better to use the -agentlib:jdwp single option


    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

Friday, 6 May 2016

Ant script to run maven clean and maven install commands

Following is an useful ant script to run the frequent maven commands using the m2 plugin in eclipse,

  <target name="maven clean">
      <artifact:mvn mavenHome="${maven.home}" fork="true">
          <arg value="clean" />
      </artifact:mvn>
  </target>

  <target name="maven install">
      <artifact:mvn mavenHome="${maven.home}" fork="true">
          <arg value="install" />
      </artifact:mvn>
  </target>

  <target name="maven clean-install">
      <artifact:mvn mavenHome="${maven.home}" fork="true">
          <arg value="clean" />
          <arg value="install" />
      </artifact:mvn>
  </target>

This will be useful for projects using maven and ant as build tools.

Saturday, 20 February 2016

Print all the request parameters map in java

This piece of utility code would print all the key-value pairs in the request object.

 Map<String, String[]> params = request.getParameterMap();

 Iterator<String> i = params.keySet().iterator();



 while ( i.hasNext() ){

 String key = (String) i.next();

 String value = ((String[]) params.get( key ))[ 0 ];

 System.out.println("Requst Params Key: ["+key+"] - Val: ["+value+"]");

 }


Here in the above code "request" is an object of "HttpServletRequest".

Wednesday, 10 February 2016