Most such things are hardware faults and wired into the hardware. I have seen some software stuff you can fake out on a few devices but it is super rare.
What "tricks" have you tried? Most of the time it is either fluff in the port, or the little spring that inserting the jack causes to contact has lost its spring and can be teased back out (putting the headphones in will see it happen again though) or possibly even broken off.
Forest for the trees. Assuming you don't just yank the thing off there then you can probably drive the speakers from the headphone jack if it is going to pretend they are plugged in. Fly some wires from the headphone socket to the speakers and problem solved. Let's not go there, or do the related idea of trace cutting, though.