Pretty simple: .jar
-Files aren't executable by themselves. The JVM is a runnable. A workaround would be to write a wrapper-application in for example C
or C++
and compile it to an executable. Or use a wrapper-library like launch4j. You can find more info about those wrappers here: wrapper-libraries for java
If you absolutely want to edit the file-associations from within your java-app, you can use JDIC to do that task.
boolean editDefaultApplication(){
AssociationService serv = new AssociationService();
//try to remove old association
Association logassoc = serv.getFileExtensionAssociation(".mp3");
try {
serv.unregisterUserAssociation(logassoc);
} catch (java.lang.IllegalArgumentException | AssociationNotRegisteredException | RegisterFailedException e) {
e.printStackTrace();
return false;
}
//add your own application as default
logassoc.addFileExtension(".mp3");
logassoc.addAction(new org.jdesktop.jdic.filetypes.Action("open", "<path to wrapper executable>"));
try {
serv.registerUserAssociation(logassoc);
} catch (java.lang.IllegalArgumentException | AssociationNotRegisteredException | RegisterFailedException e) {
e.printStackTrace();
return false;
}
return true;
}