There is a program named jpegtran
jpegtran – a utility for lossless transcoding between different JPEG formats.
To rotate the image losslessly, you can do the following:
$ jpegtran -rotate 180 -perfect -outfile rotated.jpg origin.jpg
And Here is a list of applications which provide the JPEG lossless rotation feature based on the IJG code