If the country in question is attacking first. Essentially, that means a war on the turf of my own country, or on the turf of one of my nation's allies.
9/11 doesn't count. We were attacked by a group of people living in a country, not a country itself.