BERLIN — Tesla received approval from a German court to continue to cut down forest near the capital Berlin to build its first European car and battery factory, in a defeat for local environmental activists.

The court said in a statement on Thursday it had rejected urgent applications to stop the land being cleared of trees from several environmental groups, adding its ruling was final. It had temporarily halted the tree felling earlier this month.

The U.S. electric car maker announced plans last November to build a factory in Gruenheide in the eastern state of Brandenburg that surrounds Berlin, a decision that was initially lauded as a vote of confidence in Germany.

However, local and national lawmakers were caught out by the strength of opposition to the factory, with hundreds of demonstrators protesting over what they say is the threat it poses to local wildlife and water supplies.

Lawmakers from Germany’s pro-business Christian Democrat and Free Democrat parties had warned that the legal battle waged against the factory would inflict serious damage on Germany’s image as a place to do business.

Tesla plans to build several models at the new plant starting with the Model 3 sedan and Model Y crossover, with more cars to follow. The factory is due to open in July 2021.