How can I rotate the barrel like so, in the first image below?

I want the barrel to rotate 45° so that the shotgun shells can be put into the barrel. But when I rotate, I get this image below:

How can I rotate the barrel like so, in the first image below?

I want the barrel to rotate 45° so that the shotgun shells can be put into the barrel. But when I rotate, I get this image below:

Thats because the "Origin" of the barrel is all the way to the right of the screen. Every object has an "Origin" and it is the yellow dot that appears every time you select an object. Here is a tutorial to explain what an origin is and how to change it. - https://www.youtube.com/watch?v=0FxrRdbk854
Is there a way I can combine all objects using join and still have the barrel pivot over the x axis?
– Jan 04 '16 at 01:16If you want to avoid using bones, and only animate the rotation, then I would use the 3d cursor as your pivot point. 
This answer is guessing your barrel was once the same object as the stock, and you separated them. If not, I'm sorry I could not be of a help.
When creating a object, an origin point is made in the center (usually) and if you were to go into Edit mode and work away, as you have, then at one point decide to CtrlP to separate the two objects (in this case, your barrel and the stock) later on in your model, then your separated object will have the same origin as the other.
Causing it to rotate at the wrong position.
I may of said that too confusingly, so I'll just say the solution now.
First, I created a very bad remake of your model, as it's currently 5:02 AM.
It took me 3 objects to spawn in, a cube, and 2 cylinders. I shift clicked the two cylinders and held CtrlP to separate them into two objects.
At this point, I have what I believe is your current situation. To fix this, I selected the back faces of the barrel, and pressed ShiftS and set my 3D cursor to the median point of the selected faces. (cursor to selected) I then entered Object mode and pressed ShiftAltCtrlC and selected Origin to 3D Cursor
The barrel now rotates from there.
This is perhaps unhelpful, and I'm sorry if this is unclear or such. I shall add a gif tomorrow explaining the process. hope as someone could edit this for me, as I must sleep. Good luck in your efforts!