Sounds like you're converting from an internal-slip 249 to an external-slip 242. There's 3 variables that determine rear drive shaft length: TC slip yoke style, rear diff model, and transmission length.
The external slip TC is about an inch or so longer than the internal variety, so the drive shaft will need to be that much shorter. Your 4.0L had the external slip TC, but also has a D35 that is an inch or so shorter than the 5.9's D44A, so that's an approximate wash. It also has the 42RE trans that is shorter than the 46RE in your 5.9, so its rear drive shaft may actually be longer than your 5.9L's.
The only way to tell for certain is to measure after you've got the 242 installed. My guess is that neither shaft will be the correct length, and the most straightforward fix would be to have the 5.9 shaft shortened, thus avoiding the conversion U-joint needed to use the 4.0 shaft.
1994 5.9L ZJ, retrofitted UC package, NP242 swap, 17" JK Moabs with 32" BFG MT KM's.
The Jeep of Theseus