St Augustine wrote two criteria for Just war, but Aquinas is credited for writing them clearly and adding the philosophy. He also contributed the third criteria, ‘right intention’. Other Christian philosophers debated new criteria over the next 500years and eventually, five rules were agreed
The war must be started and controlled by the state or its ruler (e.g. a king). This is called the ‘legitimate ruling authority'.
This tends to rule out most civil wars and terriost campaigns as the ruling authority may be in question or because there is no process for determining the people's will regarding the war. The condition goes back to Aquinas and before him, Augustine.
There must be a just cause with a chance of winning e.g. In World War 2, the allies decided the cause was just, and defended countries from German attack.
This does not necessarily rule out hopeless wrs if the values involved are important enough, but again demands a careful assessment of the consequences.