Especially after the Battle of Hakusukinoe in 663, the Emperor Tenchi ordered the constructions of Mizushiro (castles on lakes or marshes erected for defensive reasons) and Yamashiro (castles built on the top of mountains or halfway up the mountains for defensive reasons) throughout the country in preparation for invasions by the Tang Dynasty and the Silla (ancient Korean Kingdom).
特に663年の白村江の戦いの後、唐や新羅による侵攻に備え、天智天皇の命で各地に水城や山城が建設された。