Run Maven2's Jetty Plugin on Different Port

Maven2's Jetty Plugin default port is 8080, to run on different port ( e.g. port 9090 ) we can either:


1. Using command
Add option -Djetty.port=9090 on command.
example:
mvn -Djetty.port=9090 jetty:run

2. pom.xml
Change/add jetty.port system property on pom.xml.
example:

 org.mortbay.jetty
 maven-jetty-plugin
 
  
   
    jetty.port
    9090
   
  
 

Get Current Month As Number in BASH

Use bc to convert month from current date to eliminate character zero ('0') when returned month is under 10.
This useful when you need to do some numeric operation using month.

sample :

# retrieve month ( assume current date is September, 17 2012 )
M1=`date -%m` # result: 09
M2=`date -%m|bc` # result: 9

# numeric operation
let "M1=$M1-1" # error: -bash: let: M1 = 09: value too great for base (error token is "09")

let "M2=$M2-1" # result: $M2 is 8

Hide class files on Eclipse's Open Resource Dialog

Problem:
When start typing criteria on Eclipse's Open Resource dialog (Ctrl+Shift+R) sometimes .class files shown on Matching Items's box.  In my case they are only compiled JSPs not regular Java's classes.

Solution:
Mark folder containing .class files as derived. In my case, i marking 'target' folder (yes it's maven project), and here's the steps:
  1. right click the folder on Project Explorer,
  2. click on 'Properties',
  3. check 'Derived' under 'Attributes' part.
  4. click 'OK', 
done, the .class files won't shown on Open Resource dialog again.

Derived attibute on foder properties


If .class file still shown then you might want to:
  1. examine Open Resource menu (accessed by clicking triangle button on dialog's top right) the 'Show Derived Resources' should be  unchecked.
  2. find another folder containing .class files and check their 'Derived' property.
access to Open Resource's menu

Calculate days in BASH

I need a quick ways to calculate age in days from a given date, so i use this command:

echo \(`date +%s`-`date -d '2012-04-01' +%s`\)/86400 | bc

Copy a Symbolic Link on Linux

The Problem:
I can't use cp to copy a symlinks to a directory, but i don't want to re-create it which could lead to typo problem due to long target path.

The Solution:
After quick search i found two working ways to do it.

First,
you still need to re-create then link but doesn't have to re-type target path, use readlink output instead.

ln -s `readlink ~/v1/jboss-deploy` ~/v2/jboss-deploy

In above command the `jboss-deploy` is a symlink to a directory somewhere in this box.




Second,
just use -P option on cp


cp -P ~/v1/jboss-deploy ~/v2/

well, then i should admit that i never read cp manual carefully... =="

git diff's ESC chars problem on xterm

First time using git diff on xterm, the displayed result showing ESC[ characters instead of colored line.




Found this after searching, and after checking less man pages i concluded that i only need -R options since i only want to clear ESC[ characters and colored diffs. So i add this line on my ~/.bashrc :

LESS="-R"; export LESS


and here is the result after re-login: