The "just war" theory was developed over the centuries by Christian philosophers and theologians, chiefly Saint Thomas Aquinas (the doctor angelicus), Saint Augustine, the School of Salamanca.
This doctrine asserts that the use of force should not be completely ruled out since peacefulness, when we are confronted by a grave wrong that could only be stopped by violence, is a sin. There are cases when defence of oneself or others may be a necessity.
But, because war is one of the worst evils endured by mankind, the use of force should always be subject to strict conditions, including the following.
War should always be defensive.
There should be a reasonable chance of success. If failure is a certainty, then it is just an unnecessary spilling of blood.
War is only legitimate as the last resort, all peaceful means of achieving the war aims, like dialogue and negotiations, must be exhausted first.
There must be a just cause and purpose. A just cause would include self-defence, protection, prevention of an even greater evil and preventive war against a tyrant who is about to attack, but not self-gain, power, revenge, greed or pride. There was no just cause when Hitler invaded Poland in 1939 with the purpose of obtaining land, or in the Boer war in which the British immigrants rebelled against the Afrikaans as a feebly disguised attempt to annex South Africa to the British Empire.
Law and order must always be restored, and it is obligatory to go back to normal life after the war.
It is imperative to use proportionate force, namely that the response be commensurate to the evil. Use of more violence than strictly necessary would represent an unjust war. Civilians must be spared. This was not the case in the bombing of Nagasaki or Hiroshima, when thousands of non-combatants were killed.
There are moral limits to action in war. It is not permissible to kill hostages or attack innocents.
Just war must be waged and authorized by a legitimate, properly instituted authority like the state.
Even when legitimate governing authorities declare war, their decision is not a sufficiently just cause to start a war. If the people oppose a war, then the war is illegitimate. The people have a right to depose an authority or government that is waging, or is about to wage, an unjust war.
The just war theory later developed into international law theory, founded by jurists like the Italian Alberico Gentili and the Dutch Hugo Grotius.
This codified a set of rules which still today frames the fundamental principles of war and international law.
It is interesting to note how much our current legal and moral ideas owe to our Christian traditions.