Japan attacked Pearl Harbor and Hitler attacked Russia for the same reason. They were both forced. @Darth Algar was on the right track. The Japanese Pacific rampage was driven by the simple fact that the island nation was destitute of the natural resources necessary to sustain a modern industrial power. So they looked around and decided on the same solution which had served the other island great power in similar circumstances. They (like the Israelis) simply arrived at the solution too late in the game to be tolerated. The “Greater East Asia Co-prosperity Sphere” (you gotta love that one) was their clever euphemism for the rape of Asia and the Pacific. And it solved the crucial petroleum issue (the most immediate choke hold on modern living) through seizure of the Dutch oil fields through the conquest of Indonesia, yielding huge additional bonuses such as rubber and tin. But it was when we slammed the door on access to our iron, steel, scrap etc. that they saw the writing on the wall. The other trait Japan shared with Great Britain (and for the same reason) was a formidable shit kicking navy second to none, along with a merchant fleet one would expect for world domination. It is interesting that in the run up to Pearl Harbor, the warlords were stridently advised by those flag officers, ambassadors, etc. who had actually spent time in the United States that messing with the place was suicide. Yamamoto suggested that before hazarding such an adventure proponents take the tour (as he had) of Ford’s River Rouge complex then on the outskirts of Detroit.
On to Germany. Superficially, it might appear that Hitler was crazy to invade Russia. But he was confronted by the same problem as Japan, only he had ample reserves of the crucial components for modern civilization such as coal and steel, plus the most sophisticated chemical industry in the history of the world, capable of synthesizing much of everything else. The one big missing chink was again oil, the lack of which meant looming near term catastrophe. In many respects Hitler was a genius. He understood better than most of his generals that there would be no more oil from Venezuela or North Africa with the Royal Navy between him and those oil fields, and he was now stuck owning a Europe running on oil & gasoline, with no way in hell to synthesize enough of the stuff from coal. He was also confronted with the prospect of feeding all those people minus imports from abroad. Thus—the soviet oil fields in the Caucuses & the breadbasket of the Ukraine were not only vital, but had to be overrun quickly and soon. North Africa was the other possible source along with some dribbles from Romania, but the problem with Africa was once again the British navy and while Ploesti could not supply the load. Most people don’t realize just how close to the wire Germany operated with what was unquestionably the preeminent military machine of the modern world perpetually running out of gas. Clues to the actuality of this can be realized from photographs of elite mechanized units and their horse drawn supply trains (and sometimes artillery). German production of tanks & weaponry rose steadily despite Allied saturation bombing. What did not rise was the sufficiency to fuel them. The world’s military museums can thank this fact for the quantity of Wehrmacht tanks on display simply because they were abandoned when they ran out of gas.