In 1807, following the French invasion, under the command of General Jean-Andoche Junot, the Portuguese Cortes escaped to Brasil, at a time of when Stocker was secretary of the "Real Academia das Ciências" ("Royal Academy of Sciences"). He was one of the dignitaries, in the name of Regency, who travelled to Sacavém to receive the invader. This attitude, as well as the election of Junot as a member of the Royal Academy and Stockler's personal presentation of his credentials while secretary of the Academy, resulted in his being labelled as collaborator (while putting him in the confidence of the French). Accepting from Junot the command of the battery of Areia, near Belém, his force impeded the departure of the Portuguese naval shipping for Brazil, thereby proving his alignment with the French.