How would I make my Java application delete itself and then close out of itself on a Mac/Linux OS? I have tried a couple Runtime commands, but none of them seem to work.
Something like this maybe:
try {
Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "rm \"" + getRunningJarPath() + "\""});
} catch (final IOException e) {}
Note: The method: getRunningJarPath IS accurate.
Generally, it’s not possible: you program may happen not to have rights to remove itself.
Additionally, there’s a problem: while your program is running, JVM holds a read lock on the JAR, so it well may be that you cannot delete it right away.
Usually, you run your program from a script which would check the exit code and remove the files if necessary.