A judge in Mercer County on Thursday ordered two affluent New Jersey towns to plan for more low- and middle-income housing within their boundaries, a long-anticipated ruling some say might force municipalities statewide to build more affordable housing.

In her decision, Superior Court Judge Mary Jacobson endorsed a methodology that concluded that the state should add 155,000 affordable housing units by 2025. The number is less than housing advocates sought, but more than towns wanted.

"Lower-income households are not going to be excluded in the way that lots of wealthy towns hope to," said Kevin Walsh, executive director of the Fair Share Housing Center, a Cherry Hill-based nonprofit that advocates for affordable housing and is a party to the case.

Princeton and its neighbor West Windsor are among the state's wealthier enclaves — with median household income at $167,000 in West Windsor and $118,000 in Princeton, according to census data.

Jacobson determined that Princeton should have 753 new affordable units — more than double what the town contended, according to Fair Share — and that West Windsor was responsible for 1,500, also far higher than its own calculations.

While her decision only applies to the two Mercer County towns, other municipalities have been awaiting the ruling as they grapple with how much affordable housing they must provide under the New Jersey Supreme Court's longstanding Mount Laurel cases.

The cases have required communities to accommodate housing that lower- and middle-income households can afford. But calculating how much housing each municipality is required to provide — whether by zoning, redeveloping existing housing or building new units — has been a battle.

After years of failure by the state to enforce the housing requirements, the state Supreme Court in 2015 directed municipalities that hadn't met their obligations to submit plans for doing so to county-level Superior Courts.

Since then, 190 municipalities have reached settlements, according to the Fair Share Housing Center. But more than 100 others haven't resolved their obligations — which weren't specifically defined by the Supreme Court's 2015 ruling, or another ruling last year that found towns still had to meet housing needs that accrued during the 16 years the state wasn't enforcing the requirements.

Jacobson's decision was 217 pages and followed  a 40-day trial last year with conflicting expert testimony projecting New Jersey's future population and housing needs. It could spur other towns to settle, Walsh said, although other trials may also be held.

Frank Marshall, staff attorney for the New Jersey State League of Municipalities, said Thursday the league was still reviewing the decision.

The housing center, which disagreed with some of Jacobson's findings, could appeal the decision, as could Princeton or West Windsor. In response to the order, the towns must submit plans for meeting the obligations, according to Fair Share.

West Windsor Mayor Hemant Marathe said Thursday that he needed to talk to council members, but said he was "a little puzzled" by the decision. He said an expert appointed by the court determined West Windsor's affordable housing obligation was only 1,000 units — 500 fewer than her order specified. Fair Share had argued the township owed 1,900 units.

"It makes a laughingstock of the expert," Marathe said. He said there was "not that much demand" for housing in West Windsor, which Marathe said has about 10,000 homes.

"That's why the common man is fed up with this whole political process and both parties. They are just divorced from reality," Marathe said.