This cannot be achieved from Java. Well, at least without administrator rights. Windows show icons for file extensions by taking values from Windows Registries. The thing is that, when an icon takes place, it must take for all users according to this link. In the link, HKEY_CLASSES_ROOT
is referred in order to achieve that. That's where the "administrator rights" part come. It's worth to mention, without being 100% sure, that a .JAR file (a java application) can be executed with admin rights, only if you execute cmd
as administrator and then java -jar myapp.jar
. I had spend a lot of hours one day in order to edit these registries from Java and i did not manage to do it without administrator rights. (If you do it, let me know how you did :) )
Now, assume you have admin rights, one way, would be a simple
reg
command from admin privileged cmd
.
As described in the previous link though, you cannot simple (i am not so sure) change the icon for a file extension, without giving the full path of your program's executable (.exe
). Yes, you guessed it right, your program, is not a windows executable. It is just a compressed file. So, this gets rejected as well.
Now, your problem heads right to How can I convert a JAR file to an EXE file?. Then, plus the admin rights, you might be able to do it.
My personal advice though, is to find a JAR to EXE converter which gives this option during program installation. I mean, i am sure you have seen in a windows installation something like "Associate .txt files with Notepad ++".