Associate File Extension with Java Application

Ploug picture Ploug · Mar 22, 2014 · Viewed 11.7k times · Source

[1 file extension (.atb) and one jar file picture

Here is a picture of the 2 files in question, one .atb and one .jar

If i just click the jar file, it opens my program smoothly, no questions asked. If i click the New Text Document and choose "y" as my default program, it says this:

picture of message

If i do all this with .txt as file extension it says the same, still doesn't work.

If i do all this in Windows 7 with the same setup, it all works fine.

Also i checked my event logs when this occurs and this pops up as a keyword "Audit Success" with the text: "An attempt was made to query the existence of a blank password for an account."

Do you have any idea what might cause this?

Answer

vallentin picture vallentin · Mar 23, 2014

You can't associate file extensions to trigger a .jar file on Windows. The only file types you can trigger on Windows are .exe, .pif, .com, .bat, .cmd, so instead of triggering the .jar file, you can trigger a .bat file, which then launches the .jar file.

Create a y.bat file and place it next to your y.jar file and write the following code inside it:

@echo off
title y
start javaw -jar "C:\Users\SomeUsername\Desktop\y.jar" %1

You can change the title and y.jar path as you please, just remember that the path need to be the absolute path. Though the real keyword here is %1, that is the actual path, of the file you clicked.

You can get the value of any parameter using a % followed by it's numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on

%* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...%255)

Now you can simply right-click on any .abt file and press "Open With...", remember to check "Use this app for all .abt files" and then just browse for the y.bat and click "Open". Now each time you double-click a .abt file it will launch your .jar program.


Additionally I've written this post (Associate File Extension with Java Application) after writing this answer.