The Just War Doctrine is an ethical criterion to ascertain if a particular war is indeed morally permissible. If it is evidently clear that a war, battle, or specific order is immoral, then it must not be complied with, lest the person become a material cooperator in evil.
Saint Augustine (fourth century AD) and Saint Thomas Aquinas (thirteenth century AD) developed a system by which any citizen or leader can ascertain the morality of a war in question.
Since moral theologians have always believed it was morally right to defend yourself and your family from unjust aggressors, then it was not too difficult to see that nations had a similar right to defend their citizens from foreign or domestic enemies. The issue of warfare, however, can sometimes get complicated.
The Catechism (#2309) lists the four requirements of a just war:
Damage inflicted by the aggressor on the nation or community of nations must be lasting, grave, and certain;
All other means of putting an end to it must have been shown to be impractical or ineffective;
There must be serious prospects of success;
Use of arms must not produce evils and disorders graver than the evil to be eliminated. The power of modern means of destruction weighs very heavily in evaluating this condition.
More elaborate refinements can be found in Catholic textbooks on moral theology and ethics. Refined distinctions have been made for the period prior to going to war (ius ad bellum) and for what happens once war has begun (ius in bello).
Before going to war (ius ad bellum) there must a just cause to initiate war; the decision to go to war must be made by a competent authority; there must be comparative justice (is this particular war worth the risk of life and property?); right intention (it must not be a war of revenge or retaliation nor to gain territory, but to defend against an unjust aggressor); the option must be the last resort (diplomatic and economic measures must be tried first); and probability of success (fighting an unwinnable and impossible war is wrong) and proportionality must be considered.
During war (ius in bello), there must be proportionality (only as much lethal force as is necessary to achieve success) and discrimination against non-combatants (formerly this referred to distinguishing civilians from military personnel but this is no longer applicable since often enemies do not wear uniforms as such and sometimes civilians have guns, making them combatants as lethal as armed soldiers).