I had this problem, also on a 98 5 speed. The j-shift selector, when I would shift to 4wd, was not activating the solenoid switch. I removed that switch from beneath the shifter, cleaned it up on my workbench, reinstalled and voila.
Perhaps that may be it for you as well?