COLORADO SPRINGS, Colorado (CNN) -- President Bush told the 2008 graduating class at the U.S. Air Force Academy on Wednesday that the "only way America could lose the war on terror is if we defeat ourselves."

Speaking on a cloudy day at Falcon Stadium, the president compared the wars in Iraq and Afghanistan to America's earlier conflicts, particularly World War II.

"Our nation is once again contending with an ideology that seeks to sow anger, hatred and despair: the ideology of Islamic extremism," he said.

"In today's struggle, we are once again facing evil men who despise freedom and despise America and aim to subject millions to their violent rule.

"We assumed this obligation before," he said, referring to the rebuilding of Germany and Japan after World War II, a conflict that saw the loss of more than 400,000 American lives. Watch more of Bush's speech »

"Germany and Japan, once mortal enemies, are now allies of the United States. And people across the world have reaped the benefits from that alliance," he said. "Today, we must do the same in Afghanistan and Iraq. ... We'll lay the foundation of peace for generations to come."

But today's wars differ from those of the past, Bush acknowledged, and not only because of modern technology that allows "greater precision" in warfare.

Don't Miss

"One challenge is that in the past, in Germany and Japan, the work of rebuilding took place in relative quiet," he said.

"Today, we're helping emerging democracies rebuild under fire from terrorist networks and state sponsors of terror. This is a difficult and unprecedented task -- and we're learning as we go."

The measure of success in war has changed, he said.

"In the past ... there were public surrenders, a signing ceremony on the deck of a battleship, victory parades in American cities. Today, when the war continues after the regime has fallen, the definition of success is more complicated."

Nonetheless, he said, in Iraq and Afghanistan, there is a clear definition of success: when those countries are rid of al Qaeda, when they are economically viable, when they are democracies that can govern effectively and when they are strong allies on the war on terror.

"These successes will come," he told the class. "And when they do, our nation will have achieved victory, and the American people will be more secure. "