It's not the battery in the key, as the transponder doesn't require a battery.
If the JK in question has an automatic transmission, it has "TipStart", which means it will continue to crank after letting go of the key, until it starts, or 10 seconds if it fails to start.
Starting, then shutting off in a couple seconds usually means the wireless control module has not recognized the key.
Have a spare key handy next time it happens. Try the spare key after the first start failure with the regular key. That should tell you if the problem is the key or the wireless control module.
If it happens with both keys, go under the hood and pull up on the large white fuse holder in the fuse box, then reseat it after a few seconds.
This will reset the wireless control module if that is what it needs.
2008 Unlimited Rubicon Automatic