45 degrees is only good if you have no drag. With drag present, the optimal angle is lower. Reference: artillery tables based on farthest point of reach. An overview of what is in them could be read here, however a picture there showed general distance travelled to actually peak at 45 degrees ("phi" curve). The pic referenced:
Angles are in degrees on the left.
You here have a gravity-based "artillery" with top speed attainable at about 105 m/s (used this calc with 10-cm round stone orb with 2500 kg/m^3 density), but you won't be able to convert all of it into "muzzle velocity" regardless of your ramp's construction. First, if the ramp would have a lowermost point, which it must have in order to curve the already energized ramp-ball to change speed without getting broken, then the terminal velocity could only have been reached right there (or rather a little before that point, as friction and drag would start eating more energy than the gravity would give to it while it still descends the ramp at low angles), this in turn means that the best speed would be attained at a slightly negative angle of the ramp, taking away distance even if the ramp's exit point would be pretty high. Second, as the answer by L.Dutch pointed, the ball would be launched with significant energy in its momentum of spin, and this rotation of the ball would pull it downwards, lessening firing distance even further. Third, your mountain is only as high as it stands, so you only have as much initial potential energy to convert, and it goes two ways, acceleration and rotation, the latter effectively going against you (so maybe make a sliding ramp instead if feasible?). And final from what I can see, that the balls of yours are made of stone, a rolling stone could well break before reaching terminal velocity due to impurities, cracks and/or uneven tension generated by rolling.
Now. The energy stored in rotation for a uniform sphere of mass m and radius r, rotating at speed w is 0.4*m*r^2*w^2. Since for a sphere that's rolling down the slope r*w=v, where v is linear speed of its mass centre along the slope, the total energy conversion from potential splits the energy of fall into 1 part of speed and 0.8 parts of spin, making the height required be 1.8 times larger just in order to reach the terminal speed, less drag and friction. So for a mountain 1 kilometer high the maximum speed the ball can reach by free-rolling would be sqrt(2*g*h/1.8) or 104 m/s, about equal to terminal velocity. This in turn means that any ramp length above 1.0 km high (and some margin I can't calculate as it depends on drag and friction) would lose more energy than provide by height difference.
And finally, you need you ramp to be able to be turned both by elevation angle and by rotation angle, otherwise your balls would fly predictably long, meaning that your enemies would know where your balls would land and thus avoid going there. The elevation angle can be adjusted with relative ease, as the lowermost profile is somewhat straight relative to the ball's axis of spin, thus adjusting this would only result in changing the force that the ball applies to the ramp while curving upwards. The change of azimuthal angle would involve that ball to pitch, losing energy to alter its already high spinning momentum, thus it would be best applied at the top, yet turning the entire 1.5-km long ramp would be too hard to accurately implement, and any smaller alterations would put a great strain over the part of ramp in contact with an off-spinning stone ball, probably resulting in damage to the ramp and inaccuracy of the ball, as it might not fully reach the new course until going off the ramp one way or the other.
In short, such a ramp can gain your mountain dwellers a hardly controllable range of fire of about 1300 meters at best, but since it's wood and stone, it might not be sturdy enough to actually launch enough stones at any incoming invaders before they reach the ramp, and once there, it would provide a great shelter for them from the avalanche above that would otherwise deliver quite some damage. But if that happens, a smaller removable ramp with negative release angle could be used to direct the same stones into destructing the ramp together with whoever hides underneath (compare ski trampoline with its slope).