The war described in Mahabharata was fought in righteousness.
The rightful kingdom of Pandavas were denied to them by Kauravas. They asked for half of the kingdom, but denied. Then they asked for 5 villages, then reduced the demand to 5 house in that kingdom. But even that was denied by Kauravas. Before the war, Sri Krishna went to the Kauravas as peace messenger, but Duryodhana was not willing to accept even the smallest of their demands. Duryodhana said they will not even give an inch of land to Pandavas.
Apart from these, the Mahabharata war was in the making for a long time than this. War started when even when they were young, Bhima was attacked. The enmity was long standing.
A point to note is that king Dritarashtra was partial and did not correct his children when they were involved in adharma. Instead his attachment to his sons overpowered his discriminative power.
Finally, there was no option other than war.
When the war started, Arjuna, upon seeing relatives, he is unable to perform his duty as a warrior. Arjuna was respected and feared by enemies too. They had very high respect for his abilities as a warriors. But, though Arjuna, as a warrior was supposed to fight for dharma, he was not able to do so.
A nice way to understand this is through a simple example. He came to fight (his dharma), but didn’t want to fight seeing his relatives and he wanted to take sanyasa (which was not his dharma). Sri Krishna cleared the confusion and asked to do his duty. Since Arjuna was a warrior and his duty was to fight against adharma, he fought the war.
This is equally applicable to any other profession and person too. We many a times prepare to do our dharma, but seeing the enormity of task or the hurdles we try to run away from them to take up someone else’s dharma. This is the confusion that Sri Krishna clears through Bhagvad Gita.
Gita is not talking about war. Interestingly, never in the history has anyone gone for war after reading Bhagvad Gita, rather it has inspired millions to stick to a life based on dharma.