Associate File Extension with Java Application
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:
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?
Solution 1:
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.
Solution 2:
You can get by without a bat file by running from the command line (with admin privileges)
assoc .xox=Xoxfile
ftype Xoxfile=C:\Program Files\Java\jre1.5.0\bin\javaw -jar c:\dev\work\y.jar %1
(correcting for the path to your current jre and path to your jar).
Since .txt is already a defined filetype in windows, I think you could skip the assoc command and replace Xoxfile above with
ftype "Text Document"=C:\Program Files\Java\jre1.5.0\bin\java -jar c:\dev\work\y.jar
but I've only done this with a new custom file type.
https://www.rgagnon.com/javadetails/java-0592.html