The term jarhead for a Marine is an excellent example of the difficulty of tracing slang terms back in time. There are several theories as to its origin, none dominant. But another interesting principle of word persistence is in play with jarhead: the origin of a word may not explain its persistence. Where it originally comes from is in dispute, but its reemergence in popularity is clear.
Many sources indicate that it was sailors who gave marines the nickname, and that it was common in WWII. As marines were specialists in amphibious landing and were thus often in contact with the Navy, this adds up. There is a written reference from 1933 of a sailor calling marines jarheads.
The prevailing theories are
1. A variant of jughead/jawhead, a term for a mule, used with mixed insult and affection for marine toughness, stupidity, and difficulty in getting along. This would date the term back into the 19th C, in all likelihood, when the armed services actually did use mules a fair bit.
2. The tight-collared dress blues gave them the appearance of a mason jar with rubber or leather seal (and so might be a less-complimentary version of leatherneck). As mason jars were often blue in the first half of the 20th C, this gains some possibility. This is not mutually exclusive with #3.
3. The wide flat "cover" of the marine could be easily compared to a jar lid.
4. The high and tight haircut of marines also gives a jar lid appearance.
Let's look at each of these and make some guesses.
#2 looks promising, except that mason jars and other fruit jars were more pale aqua than blue. These would not immediately suggest dress blues, which are navy and have a more bottle-like appearance. Combined with the strong lidlike appearance of #3, plus the old leather collar, however, some wag of a sailor might easily have compared these arrogant interlopers on his ship to a mason jar just to take them down a peg.
#1 Jughead/jawhead/jarhead is quite possible, but would be unlikely to get started after WWI and the end of military pack animals. As the earliest attestation is 1933, this is problematic, as an earlier reference would be likely to show up somewhere. Yet the writer of the 1933 reference used the word offhandedly, suggesting that it was in general usage among sailors. That would take awhile.
To modern eyes and ears, #4 looks the most promising, as the high-and-tight is one of the most salient features of USMC appearance. However, that haircut was given mainly to marine recruits through the Korean War. After boot camp, marines let their hair grow to the common fashionable lengths of the time until the 1960's, when they dug in with a vengeance against the new longer styles. Pictures of marines from the 30's and 40's don't show the high-and-tight after boot camp.
Here is where the persistence theory gets interesting, though. Some older marines recall that the jarhead term was falling out of favor between WWII and Vietnam. It seemed a little insulting, perhaps, and less welcome. In wartime a high level of affectionate insult is tolerated among the services. Between wars, people get a little more defensive and territorial.
As Vietnam ramped up and the marines almost defiantly exaggerated their short hairstyle, the jar lid appearance became more pronounced. Jarhead came back into popularity, but with mixed review. It began to be used by anti-military types as an insult, was still used by other services as an affectionate insult, and became more common among marines describing themselves. This embracing of the insulting name to draw its fangs is a common phenomenon - consider "Yankee," "Quaker," "nigger," "cop," and "queer."
No telling where all this goes next. Slang has an unpredictable half-life.