Cartaojal enlisted as a cadet in the Royal Guard in 1771 while studying at the Royal School of Mathematics in Barcelona. Upon the declaration of war with Britain in 1779, his grenadier company was posted to the siege lines around Gibraltar. Promoted "alférez" (1783), "segundo ayudante" (1788), and "primer ayudante" (1791), Cartaojal campaigned against the French Republicans in 1793, was wounded in action, and received a colonelcy (1793) and captaincy (1795).