Collective cavity mode excitations in arrays of Josephson junctions