Just war theory
Just-war theorists combine a moral abhorrence towards war with a readiness to accept that war may sometimes be necessary. The criteria of the just-war tradition act as an aid in determining whether resorting to arms is morally permissible. Just-war theories aim "to distinguish between justifiable and unjustifiable uses of organized armed forces"; they attempt "to conceive of how the use of arms might be restrained, made more humane, and ultimately directed towards the aim of establishing lasting peace and justice". 
The just war tradition addresses the morality of the use of force in two parts: when it is right to resort to armed force (the concern of jus ad bellum) and what is acceptable in using such force (the concern of jus in bello). 
In 1869 the Russian military theorist Genrikh Antonovich Leer theorized on the advantages and potential benefits of war.
The Soviet leader Vladimir Lenin defined only three types of just war.

But picture to yourselves a slave-owner who owned 100 slaves warring against a slave-owner who owned 200 slaves for a more "just" distribution of slaves. Clearly, the application of the term "defensive" war, or war "for the defense of the fatherland" in such a case would be historically false, and in practice would be sheer deception of the common people, of philistines, of ignorant people, by the astute slaveowners. Precisely in this way are the present-day imperialist bourgeoisie deceiving the peoples by means of "national ideology" and the term "defense of the fatherland" in the present war between slave-owners for fortifying and strengthening slavery.
The anarcho-capitalist scholar Murray Rothbard (1926-1995) stated that "a just war exists when a people tries to ward off the threat of coercive domination by another people, or to overthrow an already-existing domination. A war is unjust, on the other hand, when a people try to impose domination on another people or try to retain an already-existing coercive rule over them."
Jonathan Riley-Smith writes:

The consensus among Christians on the use of violence has changed radically since the crusades were fought. The just war theory prevailing for most of the last two centuries—that violence is an evil that can, in certain situations, be condoned as the lesser of evils—is relatively young. Although it has inherited some elements (the criteria of legitimate authority, just cause, right intention) from the older war theory that first evolved around AD 400, it has rejected two premises that underpinned all medieval just wars, including crusades: first, that violence could be employed on behalf of Christ's intentions for mankind and could even be directly authorized by him; and second, that it was a morally neutral force that drew whatever ethical coloring it had from the intentions of the perpetrators.

Criteria: The just war theory has two sets of criteria, the first establishing jus ad bellum (the right to go to war), and the second establishing jus in bello (right conduct within war).

Jus ad bellum: Competent authority
Only duly constituted public authorities may wage war. "A just war must be initiated by a political authority within a political system that allows distinctions of justice. Dictatorships (e.g. Hitler's regime) or deceptive military actions (e.g. the 1968 US bombing of Cambodia) are typically considered as violations of this criterion. The importance of this condition is key. Plainly, we cannot have a genuine process of judging a just war within a system that represses the process of genuine justice. A just war must be initiated by a political authority within a political system that allows distinctions of justice".
Probability of success
According to this principle, there must be good grounds for concluding that aims of the just war are achievable. This principle emphasizes that mass violence must not be undertaken if it is unlikely to secure the just cause.  This criterion is to avoid invasion for invasion's sake and links to the proportionality criteria.  One cannot invade if there is no chance of actually winning.  However, wars are fought with imperfect knowledge, so one must simply be able to make a logical case that one can win; there is no way to know this in advance. These criteria move the conversation from moral and theoretical grounds to practical grounds. Essentially, this is meant to gather coalition building and win approval of other state actors.
Last resort
The principle of last resort stipulates that all non-violent options must first be exhausted before the use of force can be justified.  Diplomatic options, sanctions, and other non-military methods must be attempted or validly ruled out before the engagement of hostilities.  Further, in regard to the amount of harm—proportionally—the principle of last resort would support using small intervention forces first and then escalating rather than starting a war with massive force such as carpet bombing or nuclear warfare.
Just cause
The reason for going to war needs to be just and cannot, therefore, be solely for recapturing things taken or punishing people who have done wrong; innocent life must be in imminent danger and intervention must be to protect life. A contemporary view of just cause was expressed in 1993 when the US Catholic Conference said: "Force may be used only to correct a grave, public evil, i.e., aggression or massive violation of the basic human rights of whole populations."

Jus in bello: Once war has begun, just war theory (jus in bello) also directs how combatants are to act or should act:

Distinction
Just war conduct should be governed by the principle of distinction. The acts of war should be directed towards enemy combatants, and not towards non-combatants caught in circumstances that they did not create. The prohibited acts include bombing civilian residential areas that include no legitimate military targets, committing acts of terrorism or reprisal against civilians or prisoners of war (POWs), and attacking neutral targets. Moreover, combatants are not permitted to attack enemy combatants who have surrendered, or who have been captured, or who are injured and not presenting an immediate lethal threat, or who are parachuting from disabled aircraft and are not airborne forces, or who are shipwrecked.
Proportionality
Just war conduct should be governed by the principle of proportionality. Combatants must make sure that the harm caused to civilians or civilian property is not excessive in relation to the concrete and direct military advantage anticipated by an attack on a legitimate military objective. This principle is meant to discern the correct balance between the restriction imposed by a corrective measure and the severity of the nature of the prohibited act.
Military necessity
Just war conduct should be governed by the principle of military necessity. An attack or action must be intended to help in the defeat of the enemy; it must be an attack on a legitimate military objective, and the harm caused to civilians or civilian property must be proportional and not excessive in relation to the concrete and direct military advantage anticipated. This principle is meant to limit excessive and unnecessary death and destruction.
Fair treatment of prisoners of war
Enemy combatants who surrendered or who are captured no longer pose a threat. It is therefore wrong to torture them or otherwise mistreat them.
No means malum in se
Combatants may not use weapons or other methods of warfare that are considered evil, such as mass rape, forcing enemy combatants to fight against their own side or using weapons whose effects cannot be controlled (e.g., nuclear/biological weapons).

Ending a war: Jus post bellum: In recent years, some theorists, such as Gary Bass, Louis Iasiello and Brian Orend, have proposed a third category within the just war theory. Jus post bellum concerns justice after a war, including peace treaties, reconstruction, environmental remediation, war crimes trials, and war reparations. Jus post bellum has been added to deal with the fact that some hostile actions may take place outside a traditional battlefield. Jus post bellum governs the justice of war termination and peace agreements, as well as the prosecution of war criminals, and publicly labelled terrorists. The idea has largely been added to help decide what to do if there are prisoners that have been taken during battle. It is, through government labelling and public opinion, that people use jus post bellum to justify the pursuit of labelled terrorist for the safety of the government's state in a modern context. The actual fault lies with the aggressor and so by being the aggressor, they forfeit their rights for honourable treatment by their actions. That theory is used to justify the actions taken by anyone fighting in a war to treat prisoners outside of war.

See also: Appeasement
Christian pacifism
Democratic peace theory
Deterrence theory
Peace and conflict studies
Right of conquest
Moral equality of combatants

References: 

Further reading: Benson, Richard. "The Just War Theory: A Traditional Catholic Moral View", The Tidings (2006). Showing the Catholic view in three points, including John Paul II's position concerning war.
Blattberg, Charles. Taking War Seriously. A critique of just war theory.
Brough, Michael W., John W. Lango, Harry van der Linden, eds., Rethinking the Just War Tradition (Albany, NY: SUNY Press, 2007). Discusses the contemporary relevance of just war theory. Offers an annotated bibliography of current writings on just war theory.
Brunsletter, D., & D. O'Driscoll, Just war thinkers from Cicero to the 21st century (Routledge, 2017).
Butler, Paul (2002–2003). "By Any Means Necessary: Using Violence and Subversion to Change Unjust Law". UCLA Law Review.