Production of exotic hadrons in $pp$ and nuclear collisions