Search code examples
javajaradmin

opening jar file with admin privilege


I am getting this exception when i open jar file using cmd: java.io.FileNotFoundException: C:\Windows\System32\drivers\etc\hosts.File (Access is denied) How can i open jar file with administrator privilege? Simply double clicking the jar file does not open the jar file.I am using win7 as OS.


Solution

  • If I understand correctly, you're trying to run java from a command prompt but want admin privileges. In that case, right-click on the "command prompt" and choose "run as administrator", then you can

    java -jar myprogram.jar
    

    from the command prompt as before.

    However do you really want to allow this program to edit your hosts file? I'd recommend you find out what it's trying to do and make the change manually if you're happy with it.