Glavar was born in Ljubljana and was an illegitimate and abandoned child of the Maltese noble Pietro Giacomo de Testaferrata and of a local servant. He was raised in Vopovlje in northern Carniola. As he was a quick learner, he went to study for a priest to Ljubljana and about 1738 to Graz, where he became a master of liberal arts (). There he also got acquainted with economic theories of French physiocrats. His education was wide and he was fluent in several European languages.
