Shaler was born in Haddam, Connecticut, on March 19, 1827, son of Ira Shaler, a merchant captain. He lived much of his life in New York City beginning at the age of seven. Apparently Shaler had a private income that allowed him to pursue his own interests, and he was educated in private schools. He was active in the New York State militia, beginning as a private in 1848 and becoming major of the 7th New York Militia in 1860. Shaler published a Manual of Arms for Light Infantry, New York : T.B. Harrison & Co., 1861. With the outbreak of the American Civil War in 1861, Shaler's regiment, then called the 7th New York Volunteer Infantry Regiment, was sent to defend Washington, D.C.
After returning to New York City, Shaler became lieutenant colonel of the 65th New York Volunteer Infantry Regiment, known as the 1st United States Chasseurs. John Cochrane served as colonel. Shaler was credited by the New York Times with drilling the regiment well. The regiment left for the front on August 27, 1861. They served in the Peninsula Campaign of Major General George McClellan and then in the Maryland Campaign as part of the division of Brigadier General Darius Couch in IV Corps, Army of the Potomac. Shaler became colonel on June 17, 1862 after Cochrane was promoted to the rank of brigadier general. After Antietam, Couch's division became the third division of VI Corps. John Newton succeeded Couch. Shaler's regiment became part of Cochrane's brigade in that division. It was present at the Battle of Fredericksburg but not seriously engaged.
Alexander Shaler assumed command of the brigade in March 1863, and was promoted to the rank of brigadier general on May 26 of that year for his leadership in the field. (Joseph Eldridge Hamblin became colonel of the regiment in his place.) Shaler led the brigade at the Second Battle of Fredericksburg, also known as the Second Battle of Marye's Heights, on May 3, when VI Corps, under Major General John Sedgwick drove Jubal Early's division away from the Heights. At a crucial moment, Shaler seized a flag and led his men into the Confederate defenses. In 1893, he received the Medal of Honor for this act. His brigade also participated in the Battle of Salem Church.
In the Battle of Gettysburg, VI Corps served as a reserve for the Army of the Potomac. Shaler's brigade was sent to the right flank early on July 3, 1863. There it helped XII Corps hold Culp's Hill. Shaler's brigade usually was in reserve, but units went to the front line to help in resisting Confederate attacks. About 3:30 that afternoon, Shaler's brigade was sent to the center of the army as a reserve around the time of the repulse of Pickett's Charge.
Shaler commanded the prisoner of war camp at Johnson's Island on the shores of Lake Erie in the winter of 1863-1864, with his regiment serving as prison guards. He was back with his brigade in 1864 in time to participate in the Overland Campaign. VI Corps had been reorganized, and Shaler's brigade served in Brigadier General George Getty's second division. This brigade was on the army's right flank in the Battle of the Wilderness on May 6, 1864. At first, it was in a "refused" position facing north, thus protecting the rest of the corps. Then it was drawn into the main line of battle, supporting its fight with LG Richard S. Ewell's corps. As a result, Shaler's brigade was flanked by Confederate troops led by Brigadier General John Brown Gordon that had swung northward to attack the Union right flank. Shaler and Brigadier General Truman Seymour were among the Union soldiers captured in his foray. Shaler was trying to rally his men when he was made a captive. He was sent to Libby Prison, in Richmond, Virginia and then to Macon, Georgia. In the summer of 1864 he was placed under the fire of Union batteries bombarding Charleston, South Carolina.
After being exchanged, Shaler was transferred West where he served in the Department of the Gulf, briefly commanding third brigade, second division XIX Corps, from November 3 to December 3, 1864. Then he served in Arkansas, where he led the second division in VII Corps, December 28, 1864 - August 1, 1865, under MG Joseph J. Reynolds. This division was based at Devall's Bluff in east central Arkansas. It most was engaged in occupation of the region and minor skirmishes with Confederate forces. In June 1865, as the war was ending, Shaler cooperated in the efforts of MG Grenville Dodge, commanding the Department of Missouri, to parole the irregular forces of BG M. Jeff Thompson. Shaler received brevet rank of major general in July 1865.