can the Japanese legally build an offensive military force to counter those threats?
No. But it's trivially easy to build a large defensive force to protect yourself, your friends and your interests, even if it far away from your home territory.
https://en.wikipedia.org/wiki/Article_9_of_the_Japanese_Constitution#Reinterpretation_in_2014
In July 2014, Japan's government approved a reinterpretation of this article despite concerns and disapproval from mainland China and South Korea, although the United States supported the move. This reinterpretation would allow Japan to exercise the right of "collective self defense" and exercise military action if one of its allies were to be attacked. It is considered by some parties as illegitimate, posing a serious danger to Japan's democracy since the Prime Minister circumvented the constitutional amendment procedure, dictating a radical change to the meaning of fundamental principles in the Constitution by way of Cabinet fiat without Diet debate, vote, or public approval.
In May 2017, Japanese Prime Minister Abe set a 2020 deadline for revising Article 9, which would legitimize the JSDF in the Constitution.
(For example, the US has the Department of Defense and yet regularly invades other countries with the justification of defending US interests.)