Nuclear effects in the hadroproduction and photoproduction ofJ/ψ