Born in what was then part of Virginia (in present-day West Virginia), Jackson received an appointment to the United States Military Academy at West Point and graduated in the class of 1846. He served in the U.S. Army during the Mexican–American War of 1846–1848 and distinguished himself at Chapultepec. From 1851 to 1861 he taught at the Virginia Military Institute, where he was unpopular with his students. During this time, he married twice. His first wife died giving birth, but his second wife, Mary Anna Morrison, lived until 1915. When Virginia seceded from the Union in May 1861 after the attack on Fort Sumter, Jackson joined the Confederate Army. He distinguished himself commanding a brigade at the First Battle of Bull Run in July, providing crucial reinforcements and beating back a fierce Union assault. In this context Barnard Elliott Bee Jr. compared him to a "stone wall", hence his enduring nickname.