Why was the crossbow invented?

It was a good tool for war.