To properly resolve this issue, let's go back to the VERY basics. Which are probably not covered in much depth in VCE, but whatever.
What is work? Work is the ability of an object to exert a force over a displacement parallel to the force. Any object that is capable of doing work then has energy (this is my preferred definition of energy). Why is this directional requirement important? Defining it this way allows energy to be mathematically conserved, which makes it a physically useful definition.
So, if work is exerting a force in the direction of motion, forces that are constantly perpendicular to an object's motion should not do work. And indeed, uniform circular motion arises when the net force is ALWAYS perpendicular to the object's motion (and satisfies a magnitude requirement); the speed and thus the energy do not change in such a motion.
Now, because 2D motion can be separated into its two independent dimensions, we can consider the net force, the gravitational force, as acting on the horizontal and vertical components separately. The gravitational force is perpendicular to the horizontal velocity component, so no work is done there. It only affects the vertical velocity component. Therefore, as far as gravity is concerned, the object is only moving vertically. (it is possible to find a frame of reference such that the object is indeed only moving vertically; this frame of reference is best pictured by someone running straight under the object), and so the work it does on the object should only involve the vertical displacement.
Final question. Do we use displacements or distances? Well, suppose you throw a ball up. Gravity is clearly slowing it down when the motion is opposing the direction of gravity, and speeds it up when the motion is in the direction of gravity. Therefore, the direction of motion is important and you use displacements. It is possible to prove (I won't though) that gravity is a conservative force, which in this problem means that you only need to know the initial and final state to calculate the work; the path doesn't matter. In other words, you only need to know that the ball had a vertical displacement of 1.9 m. Any calculation involving the distance displays a fundamental misunderstanding of physics. Indeed, calculating the actual distance through the air travelled by the javelin along its parabolic trajectory isn't trivial; I invite any spesh students to do so as a preview of the coming calculus topics.