It happens when a country doesn't have enough developed institutions, and finds out that they have natural resources. Having money in the country gives comfort and freedom to public officials, and they try to stop the development of those institutions or completely destroy them. As a result, it leads to lack of democracy which itself leads to lack of economical growth. In case of Azerbaijan, the country started to export its petrol just right after getting its independence from the Soviet Union. At that time it was a new country, and didn't have any proper institution. In general, it is an unfortunate situation which is extremely hard to fix.
The only reason why the country isn't rich is because all the gains from those natural resources are being siphoned off to fund the lifestyle(s) of corrupt public officials. Nothing more, nothing less.
Azerbaijan seems to have done a better job utilizing their resources to boost the economy than most other ex-Soviet countries (including Russia, even), just looking at its economic growth since independence.
I have the same problem nowadays and think about migrating to Java for web development. I heard about Play! framework very much. Do you think Java is a good idea for web over Python and Ruby?
Actually, I find Python and Ruby much more interesting than Java (actually, Java seems as a boring language :) ) . But since Java is general purpose language and it's known as market skill, I want go for it.