Skip to content

Instantly share code, notes, and snippets.

@djangofan
Last active October 13, 2015 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djangofan/4144970 to your computer and use it in GitHub Desktop.
Save djangofan/4144970 to your computer and use it in GitHub Desktop.
Batch file to associate .jar files as self-executing.
@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: this .bat script creates a file association for executable .jar files
:: so that you can double click them to run
ECHO Creating .jar file association...
ECHO JAVA_HOME is %JAVA_HOME%
IF NOT DEFINED JAVA_HOME GOTO :FAIL
REG ADD "HKCR\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKCR\jarfile\shell" /ve /f
REG ADD "HKCR\jarfile\shell\open" /ve /f
ECHO REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%**" /f
REG ADD "HKLM\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
ECHO Finished creating .jar file association for executable .jar files.
PAUSE
GOTO EOF
:FAIL
ECHO Script failed. JAVA_HOME not defined.
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment