You *might* be able to swap it, but it's not a simple bolt-in affair. You'll likely need to address issues like:
* Computer Compatibility: The 1999 Jeep's computer (PCM) might not be compatible with the 1997 engine. This could result in drivability issues or a non-starting engine. You might need to swap the PCM, wiring harness, and potentially other sensors.
* Sensor Differences: There may be minor differences in sensors between the two engine years.
* Exhaust System: While generally the same, there could be minor differences requiring adjustments.
In short: It's *possible* with significant modification, but it's not a straightforward swap. It's highly recommended to consult a Jeep mechanic or a reputable Jeep forum before attempting this. Finding a used 4.0L from a 1999 Jeep might be a simpler and less problematic solution.