Maintaining motivation is a difficult task when performing tasks or striving for goals that are difficult in nature. We all have set goals for ourselves in the past which we either failed to accomplish or chose to not pursue once it became clear the road to success was too hard. In order to fight back against such roadblocks a person has to recognize that they will face adversity in almost any meaningful task or goal they set for themselves. A person who plans on being successful can use certain techniques to help them keep strong when things appear too difficult.
An example, if going to the gym is something one loathes then after a workout it would be keen to watch a favorite show (not eat junk food, that's counterproductive) or do something that they truly enjoy. The simple act of doing something one enjoys following a workout (assuming this is something they do not particularly enjoy) helps condition the person to continue working out and push through the difficulty of the task, for there is a reward not far ahead.
Dani Ariely, a psychologist, suffered serious burns in his youth. During part of his recovery there were complications and he was required to medicate himself. He used this simple idea of rewarding himself after this painful medication with remarkable success. This video should be able to motivate almost anyone to face down their difficulties: https://www.youtube.com/watch?v=zbEa1P4sqd8
In life there will always be hard tasks and difficult work to be done, especially if one sets a high standard for them self. Being self-aware and knowing that there will inevitably be times when giving up seems like the best option using simple "tools" to prepare for such scenarios will go a long way in helping you achieve the things you want in life.