We present a model to describe an underdamped long Josephson junction coupled to a single-mode electromagnetic cavity, and carry out numerical calculations using this model in various regimes. The coupling may occur through either the electric or the magnetic field of the cavity mode. When a current is injected into the junction, we find that the time-averaged voltage exhibits self-induced resonant steps ͑SIRSs͒ due to coupling between the current in the junction and the electric field of the cavity mode. These steps are similar to those observed and calculated in small Josephson junctions. When a soliton is present in the junction ͑corresponding to a quantum of magnetic flux parallel to the junction plates͒, the SIRSs disappear if the electric field in the cavity is spatially uniform. If the cavity mode has a spatially varying electric field, there is a strong coupling between the soliton and the cavity mode. This coupling causes the soliton to become phase locked to the cavity mode, and produces steplike anomalies on the soliton branch of the I-V characteristics. If the coupling is strong enough, the frequency of the cavity mode is greatly redshifted from its uncoupled value. We present simple geometrical arguments which account for this behavior.