objects following curve trajectory

hi
I want a train to follow a curve described by a spline function. Meaning the train can only move along the curve. The train is composed of several wagons.
I suppose I can use a joint to keep the distance between the wagons always the same. But how can I keep the wagons on the curve?

Original thread: https://box2d.org/forum/viewtopic.php?t=6640