Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file association with .jar #112

Open
pigsflew opened this issue Nov 21, 2019 · 3 comments
Open

Add file association with .jar #112

pigsflew opened this issue Nov 21, 2019 · 3 comments

Comments

@pigsflew
Copy link

pigsflew commented Nov 21, 2019

Running executable JARs requires calling java.exe -jar "%1", but when selecting the java.exe in explorer, it uses java.exe "%1", which fails.

i suggest adding something like:

manifests:

{
    [ ... ]
    "postinstall" = [ 'echo "In order to associate jar files, run sudo associate-javaw.bat"' ],
    [ ... ]
}

/scripts/associate-javaw.bat:

@echo off
assoc scoop-javaw="%JAVA_HOME%\bin\javaw.exe" -jar "%1";
assoc .jar=scoop-javaw
@tech189
Copy link
Member

tech189 commented Dec 5, 2021

I couldn't get this to work in Windows 11, sadly. Here's how I got it to work instead:

I found a program that can set file associations here (I found a scoop manifest for it here). But it needs a ProgId to be passed as the file type association, so I modified your batch file to a registry file like so:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\.jar]
@="scoop-javaw"

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw]
@="Java Archive"

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\DefaultIcon]
@="C:\\Users\\<username-goes-here>\\scoop\\apps\\openjdk\\current\\bin\\javaw.exe,1"

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\shell]

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\shell\open]

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\shell\open\command]
@="\"C:\\Users\\<username-goes-here>\\scoop\\apps\\openjdk\\current\\bin\\javaw.exe\" -jar \"%1\""

Unfortunately, I couldn't get %JAVA_HOME% to work in the registry, so the full path had to be used (replace the two <username-goes-here> with your username/scoop path if on another drive).

Once you've saved this as a .reg file and run it, then finally you can use SetUserFTA:

> SetUserFTA .jar scoop-javaw

The file association should work immediately. But for the DefaultIcon to show up you might need to restart File Explorer. Hope this helps someone.

Edited 05/09/2022 to fix reg file not adding paths to registry (needed to escape each \ and ")

@KevinNitroG
Copy link

KevinNitroG commented Jun 26, 2024

@tech189 Hi. I've customised your reg script and the icon didn't work for me. In my case, just remove ,1 in the DefaultIcon value. I'm using Windows 11 23H2 22631.3737

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\.jar]
@="scoop-javaw"

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw]
@="Java Archive"

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\DefaultIcon]
- @="C:\\Users\\<username-goes-here>\\scoop\\apps\\openjdk\\current\\bin\\javaw.exe,1"
+ @="C:\\Users\\<username-goes-here>\\scoop\\apps\\openjdk\\current\\bin\\javaw.exe"

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\shell]

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\shell\open]

[HKEY_CURRENT_USER\Software\Classes\scoop-javaw\shell\open\command]
@="\"C:\\Users\\<username-goes-here>\\scoop\\apps\\openjdk\\current\\bin\\javaw.exe\" -jar \"%1\""

Thank you very much.

@BinToss
Copy link

BinToss commented Sep 1, 2024

Scoop uses Powershell internally. For consistency, should a user-invoked post-install script be made for Powershell?

Also, note assoc is a Command Prompt command. It is not executable outside of cmd.exe. And it should be considered deprecated on Windows 8 and later.

I'm looking into the feasibility of https://github.com/DanysysTeam/PS-SFTA atm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants