To add on. The Buddha did not stop people from being in military, so to fight for defense purpose is allowable.
More details in http://www.beyondthenet.net/thedway/soldier.htm