“Why were Japanese military in China?”
Truth is Japan never invaded “China” or any nation in a modern era. “China” is not single entity but the land that had been invaded by different ethnics as Yuan dynasty(1271-1368) is Mongolian ruled China, Ming dynasty(1368-1644) is Han Chinese ruled China, and Qing dynasty(1644-1912) is Manchu ruled China who are originally from Manchuria at north east beyond Great Wall Ming built. China had been the outlawed and unsafe place to live in. Japanese military was in China under Peking protocol after Japanese was killed at Boxer Rebellion.
Qing dynasty Manchu leased Manchuria to Japan as a concession. After Xinhai revolution in 1911, Manchus lost power. Uprising Han Chinese massacred Manchus and broke Abdication Treaty with them. Manchurian royals and last emperor Puyi got kicked out of Forbidden City and escaped to Japanese legation in Peking, later moved to Japanese concession in Tianjin. Therefore Japan built Manchoukuo, a rebrand of Manchurian nation in Manchuria acknowledged by Puyi.
In 1900, Boxer rebellion besieged the foreign district of China’s capital city Beijing, assaulted and killed foreigners including Japanese legation, Sugiyama Akira. Western powers and Japan organized a multinational force to crush the rebellion.
https://en.wikipedia.org/wiki/Boxer_Rebellion
The Boxer Rebellion formally ended with the signing of the Boxer Protocol on September 7, 1901 permitting to station troops in multiple places in China for their defense.
https://en.wikipedia.org/wiki/Boxer_Protocol
In 1905, Treaty of Manchuria was made by Manchus and Japan. Manchus leased Manchuria to Japanese as a concession.
Xinhai revolution by Han Chinese in 1911 led to the end of the Manchurian rule, Qing dynasty.
When the last emperor, Puyi abdicated, Abdication Treaty was made in 1912 with Yuan Shikai. This is the international, supreme and last treaty made by Manchus, which promises to live with 5 ethnic groups of people (Han, Manchus, Mongolian, Tibetan, Islamic) in harmony representing 5 colors in flag.

Manchus agreed on no other treaty after this, and this is the overriding any other later treaties such as Nine power treaty, which was brought up later by the US Stimson to attack Japan.
The Case for Manchoukuo, George Bronson Rea in 1935
Han Chinese massacred Manchus and violated Abdication treaty.
(Below) The annual pension was never paid to other ethnics.
(Below) Manchurian tomb was destroyed and there was no punishment.
In 1925, Manchurian royals and last emperor Puyi got kicked out of Forbidden City and escaped to Japanese legation in Peking.

Later moved to Japanese concession in Tianjin, the resident Zhang Garden 张园(張園) (not open to the public) for 4 years then, Garden of Serenity/Jingyuan 静园(靜園) for 3 years until moving to Manchoukuo in 1932. Probably Manchu royals wouldn't have thought the land leasing to foreign nations(Japan) would save them and become a good hideout at the revolution.
Jingyuan 静园(靜園) is a nice traveling spot. Blog1, Blog2 .
Japanese concession, Manchuria, was in disorder and bandits terrorized Japanese railroads. These problems are rereferred to as Manchuria and Monglia disorder state problem 満蒙問題 .
Two Japanese military officers, Mongolean, and Belarusian were killed by Han Chinese at Manchuria side of area.
Han Chinese Republic of China lied, made excuses, and refused to hand over the culprits who escaped later. At any moment, the battle could have started, Japan had a justifiable cause of attack.
https://history.state.gov/milestones/1921-1936/mukden-incident
and the true invaders of Manchuria, Republic Of China and the US
The contribution to the US economy

