I too was told this story, by my father as we drove through Nobel, Ontario. While the main purpose of dynamite may never have been warfare, it most certainly was used for that purpose during his lifetime, and he didn't expect or like that very much. As well, he invented a number of other chemicals which were explicitly for use in war, but he didn't feel they defined him - he invented a lot of other stuff too. Some quotes from the Wikipedia article on the Nobel Prize:
Nobel amassed a fortune during his lifetime, with most of his wealth from his 355 inventions, of which dynamite is the most famous.
That answers your title question. Also,
In 1888, Nobel was astonished to read his own obituary, titled The merchant of death is dead, in a French newspaper. As it was Alfred's brother Ludvig who had died, the obituary was eight years premature. The article disconcerted Nobel and made him apprehensive about how he would be remembered. This inspired him to change his will.
A recent article includes pictures of the hand written will and more details on both how and when he wrote it, and how the mechanisms of the prize were put into place.
At around the same time, he met a pacifist who inspired him to change his ways from "living the high life in Paris" to something more, well, noble. In a letter to her he wrote:
Perhaps my factories will put an end to war even sooner than your Congresses; on the day when two army corps will be able to annihilate each other in a second, all civilised nations will recoil with horror and disband their troops."
(Yes, mutually assured destruction as a peace strategy, but dynamite and other explosives rather than nuclear bombs.)
So it seems your chemistry professor was close enough to the spirit of what happened and why the prize was created. Nobel was embarrassed by the way he'd been using his money, mostly as a result of his friendship with Bertha, and didn't like the idea of being a "merchant of death" because armies used dynamite (or other explosives he invented and sold, such as cordite) to kill people. Even though he thought that in theory this could reduce war, by the time he died he had set up the prizes in his will to help advance peace, science, literature and so on and thus leave the world a better place. The precise details about supplying dynamite to two specific countries in one specific war don't seem right, but the overall spirit of the story does.