The changes mark the most dramatic overhaul to Japan's security strategy since it adopted a pacifist constitution after World War Two.
It will also acquire the ability to strike enemy bases.
Under the plan, Tokyo will buy US long-range missiles capable of destroying enemy launch sites if it is attacked.
It will also increase its cyber warfare capabilities. Earlier this week, Beijing urged Tokyo to view their relationship as a cooperative partnership.
Prime Minister Fumio Kishida told journalists Japan's defence budget would be 2% of GDP by 2027.
"Unfortunately in the vicinity of our country, there are countries carrying out activities such as enhancement of nuclear capability, a rapid military build-up and unilateral attempt to change the status quo by force," he said.
"These are also now becoming more outstanding. In the next five years, in order to fundamentally reinforce our defence capabilities we will implement a defence build-up programme worth 43 trillion yen ($314bn; £257bn)."
A national security strategy document approved by the cabinet and quoted by AFP news agency described China as "the greatest strategic challenge ever to securing the peace and stability of Japan".
It also noted that China had not ruled out the use of force to assert control over Taiwan.
China's embassy in Japan responded by accusing Tokyo of making false claims about its military activities.
There are also concerns in Japan about North Korea's missile capability.
Pyongyang has fired more than 50 missiles over the past three months, including a ballistic missile over Japan in October - the first time for five years.
Meanwhile the Japanese document described the Russian invasion of Ukraine as a "serious violation of laws that forbid the use of force" which had "shaken the foundations of the international order".
A previous national security document in 2013 described China and Russia as strategic partners.
Japan's post-war constitution does not officially recognise the military and limits it to self-defence capabilities, though former prime minister Shinzo Abe expanded its role in 2015.
Polls suggest public opinion in Japan now broadly supports some form of further military expansion.
Mr Kishida's 2% of GDP figure coincides with a long-term target set by Japan's allies in the Western Nato military alliance in 2006.
While many Nato countries are still short of the target, Germany hopes to reach it in the next few years. The UK has surpassed it and is aiming to spend 3% of GDP on defence by 2030.