Wednesday, May 12, 2010

Executable .jar file is opened in an archiver (WinRar, WinZip, etc)


Something has gone wrong and when you try to open an executable .jar file by double-clicking it, the file is not executed by the JVM like it should be (before), instead it’s opened by an archiver software like WinRar or WinZip.

You can still execute the file though by manually select the java launcher through right-click – ‘Open with’ menu, but that is not the proper nor the right way to do, and nobody wants to do it that way.

This problem happens because the .jar file association has been changed to open the archiver software. The .jar file itself is an archived file (jar stands for java archive), so, not surprisingly, most available archivers out there can open it, meaning they will display the full content of it (class file, java file, manifest file, etc.) instead of running it.

Now, we need to reset the file association for the .jar file so that the JVM will be one who opens and therefore launches the .jar file, not some archivers. In order to do that in Windows XP, follow these steps:
  1. Open Windows Explorer.
  2. Open Tools – Folder Options
  3. Open tab File Types – select ‘.Jar’ in Registered File Type List – click button ‘Advanced’
  4. select ‘Open’ in the Action list – click ‘Edit’
  5. Type into textfield ‘Application used to perform action’ the following line
    ”[JAVA_HOME]\bin\javaw.exe” –jar “%1%” %*

note: replace [JAVA_HOME] with your jre path (e.g. C:\Program Files\Java\jre1.6.0_03) and don’t forget to type the quotes.

For Windows Vista/7 users, you can’t do those steps through Folder Options because the tab File Types is not available on vista/7 no more. Yet, no need to worry, there is a free software from sourceforge.net called ‘Types’ which provides an alternative way to set actions for file types. This is a very lightweight application, its current version is Types 1.3.1 and only takes 155 KiB of your harddrive. You can download it at http://types.sourceforge.net/. Below is a snapshot I took from the the download link.




There you go. You now have reset .jar file to associate with its launcher, javaw.exe, and can now run your jar file on your PC again by directly double-clicking it.

1 comment:

Radley Co Tad said...

Amazing & Great informative blog,it gives very useful practical information to developer like me. Besides that Wisen has established as Best Java Online Training India . or learn thru Online Training mode Java Online Training From India . Nowadays Hibernate ORM has tons of job opportunities on various vertical industry.