tags:

views:

78

answers:

2

Is there a java utility that can be used by an application to uninstall itself and exit? I currently only use the executable jar to test this feature on a windows platform; there is no and there may never be a fancy installation mechanism other than providing the jar file(s).

File MYAPP = new File(".\\myapp.jar");
MYAPP.deleteOnExit();
System.exit(0);

only works (deletes myapp.jar) some of the time. In the Android environment all that is needed is:

Uri packageURI = Uri.parse("package:com.co.app");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);      
startActivity(uninstallIntent);

I was hoping the desktop environment had something similar.

+1  A: 

i think you would have to write this yourself, but you could try something with File.deleteOnExit but i'm not sure if that will work. it would depend on whether the JVM has unloaded the classpath before performing the deletes.

also have a look at installer packages, eg NullsoftInstaller which can be used to create installer/uninstaller software for your software.

pstanton
I could only get deleteOnExit to work some of the time, I believe there may be a timing issue between unloading the classpath and the deletes. What I ended up actually doing is writing a function that writes, then runs a windows batch file with a short built in delay.
JackN
+2  A: 

Most likely not.

The uninstaller is usually created by the same process that created the installer, so I would look into that instead.

Thorbjørn Ravn Andersen