The first published date for "When Johnny Comes Marching Home" is 1863, sheet music and broadsides at American Memory. "Words and Music by Louis Lambert," pseudonym for Patrick Sarsfield, 1829-1892.
As Declan says, it is a welcome song, meant to be gay, only the tune re-used.