2

I am new to creating Custom URI Schemes and I am trying to launch an executable jar file using URI Schemes in my Windows 7 system.

For running this jar file from command prompt, I use this command:

java -jar demo.jar

EDIT:

For launching the same using the Custom URI Scheme, I created a .reg file with the below entry (Copied from the below post):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\DemoStart]
"URL Protocol"=""

[HKEY_CLASSES_ROOT\DemoStart\shell]

[HKEY_CLASSES_ROOT\DemoStart\shell\open]

[HKEY_CLASSES_ROOT\DemoStart\shell\open\command]
@="\"java.exe\" -jar \"C:\\Users\\John\\Desktop\\demo.jar\""

This does not works for the following reason:

The executable jar file which I am trying the run named demo.jar is a third party provided jar file and it has quite a few dependencies on XML config files which are also located in the same folder containing the jar file. I don't have privilege to change any code present within the jar file.

Using command prompt, the command "java.exe" -jar "demo.jar" works only when I navigate to the folder containing both the demo.jar as well as the dependent config xml files. BUT if I try to run the command: "java.exe" -jar "C:\Users\John\Desktop\demo.jar" from the default location of the command prompt window (which in my case is C:\Users\John) then the command does not work since the dependent config xml files are not available.

Hence I need to find out a way of changing the default location of the command prompt as well before executing the jar file.

Please suggest whether it is possible to set the command prompt default location to C:\Users\John\Desktop when I trigger the custom URI (In that case no need to navigate to a different location and the command should work fine).

1
  • I created a .txt file, changed the file extension to .reg, put the code you posted below and then double clicked the .reg file to create the registry entry. Then I verified the same in the regedit.
    – user182944
    Oct 2, 2014 at 3:40

2 Answers 2

2

Your .reg file doesn't look right. The format is very odd. It should look something more like this:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\DemoStart]
"URL Protocol"=""

[HKEY_CLASSES_ROOT\DemoStart\shell]

[HKEY_CLASSES_ROOT\DemoStart\shell\open]

[HKEY_CLASSES_ROOT\DemoStart\shell\open\command]
@="\"java.exe\" -jar \"C:\\Users\\John\\Desktop\\demo.jar\""

If this still doesn't work, double check that java is in your PATH. If it is, and it still doesn't work, try replacing "java" with the full path to the Java exe.

4
  • 1
    That cannot work either because the URL is never passed to the program. "%1" should appear at the appropriate location. Also, always use absolute paths, otherwise you’re just asking for trouble. /edit: Oh yeah, and it might also be prudent to specify a name (@ next to URL Protocol).
    – Daniel B
    Oct 2, 2014 at 13:18
  • That’s not what I meant. I was referring to the “friendly name”. It’s the default entry next to URL Protocol. You can see it in most entries in HKCR. I’ll post an answer of my own later.
    – Daniel B
    Oct 2, 2014 at 14:45
  • @Izam +1 for the help so far. When I open the command prompt, the default location is C:\Users\John. If I manually navigate to the location C:\Users\John\Desktop in the command prompt and run the command "java.exe" -jar "demo.jar" then it works fine. But if I don't navigate to the Desktop and run this command "java.exe" -jar "C:\Users\John\Desktop\demo.jar" from the default location (i.e. C:\Users\John) then it does not work since in Desktop I have some other XML files as well needed to run the jar file.
    – user182944
    Oct 2, 2014 at 16:31
  • Ok I did some application related changes and finally got this thing working, hence accepting this answer.
    – user182944
    Oct 3, 2014 at 15:34
1

So, from what I gather your main problem isn’t the actual file association but the working directory. Unfortunately, the working directory cannot be influenced when launched from a file association. If a program depends on files beside its executable, it would be broken by design were it to rely on the working directory.

Fortunately, programming isn’t just for experts anymore. ;)

The following single-line AutoHotkey script (which can be compiled to a standalone .exe file) launches a program (or .jar file or whatever). The working directory will be set to the script .exe location.

Run, hello.jar, %A_ScriptDir%

I haven’t actually tested this with a .jar file, because I don’t have JDK installed right now. I did try with an uncompiled AutoHotkey script though. Documentation on the Run command is available here.

2
  • I followed these steps: Created a .ahk file, added the entry #z::Run, demp.jar, %A_ScriptDir% in the file, Run Script and then click Windows Key + z to start the demo.jar, all these worked fine for me. But I don't want to ask my users to click the AutoHot Key manually, hence willing to automate this process to something like: When the browser starts, then the demo.jar is executed automatically. Please suggest something on this.
    – user182944
    Oct 3, 2014 at 14:16
  • You’ll have to associate the AHK script (or .exe) with the protocol, instead of java.exe.
    – Daniel B
    Oct 3, 2014 at 15:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .