Changing associations for a JAR file to run an editor

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
genestoy
Posts: 6
Joined: 07 Oct 2016 10:08

Changing associations for a JAR file to run an editor

#1 Post by genestoy » 07 Oct 2016 10:18

I need a batch file that will execute my html editor whenever any html or htm file I double click on my computer. I have already set up a batch file named runjava.bat which has the following code to start the html editor

Code: Select all

start /d "C:\Program Files (x86)\Arachnophilia" Arachnophilia.jar


That bat file starts the program ok but how do I get it to insert "any" html or htm file I clicked on into the editor? I have also done the file association for the html and htm files to start the runjava.bat file. I have searched the internet for many hours now looking for the answer so hope there is somebody here that can help me.
Running Windows 10 and editing the batch file in Notepad
Thanks

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Need batch file help please

#2 Post by ShadowThief » 07 Oct 2016 19:16

If you've set the file association correctly, you shouldn't need to do anything else.

That said, you can change your code to

Code: Select all

start "" /d "C:\Program Files (x86)\Arachnophilia" "%~1"

so that all you have to do is drag and drop the .jar file onto the batch script.

genestoy
Posts: 6
Joined: 07 Oct 2016 10:08

Re: Need batch file help please

#3 Post by genestoy » 07 Oct 2016 19:24

I am not trying to open a jar file (the program is a jar program which open fine) and I am trying to open html & htm files in that jar program when they are double clicked on.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Need batch file help please

#4 Post by Squashman » 07 Oct 2016 21:06

genestoy wrote:I am not trying to open a jar file (the program is a jar program which open fine) and I am trying to open html & htm files in that jar program when they are double clicked on.

This does not sound like a batch file problem.

genestoy
Posts: 6
Joined: 07 Oct 2016 10:08

Re: Need batch file help please

#5 Post by genestoy » 07 Oct 2016 21:16

The program opens just fine in Windows 10 and I can search for the file inside the program and it will open the html or htm files just fine. All I am trying to do is be able to double click the file in explorer and have it opened in the jar editor program (like every other type file opens in their associated program). When I try to associate the jar editor program with the html or htm files it throws an error stating Windows can not run the jar editor program (but yet it can if I open the program myself). I just thought that a batch file would do the trick. The batch file I posted above does in fact open the jar editor program just fine but does not insert the file I clicked on.
Thanks

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Need batch file help please

#6 Post by penpen » 08 Oct 2016 03:38

I first thought "This is no batch problem.", too.
But i haven't found any way to edit the context menue of the file types htm and html.
Then i tried to edit the registry ("HKEY_CLASSES_ROOT\htmlfile\shell\open\command\(Standard)" := "C:\...\javaw.exe -jar "...\Arach..."):
It failed (seems like if win10 tries to open the htm(l) file tye using javaw.exe, ignoring the command line options)!
(If i remember right, XP has no problems using such opening commands... and it also supports much easier editing... why did MS change that - or did i miss any new development?!.)

Same happens if one uses a Shortcut with the above target, and choose this shortcut as the default app to open this filetype8s) with:
It is a liitle bit irritating, that the shortcut itself works.

The only way i found, that works is to create this batch file ("Arachnophilia.bat)", and choose this as the default app to open with:

Code: Select all

start "Starting Arachnophilia.jar '%~1'" /d "C:\Program Files (x86)\Arachnophilia" "C:\Program Files\Java\jre1.8.0_101\bin\javaw.exe" -jar "C:\Program Files (x86)\Arachnophilia\Arachnophilia.jar" "%~1"
Notes:
Jar files are no executables (only zip files with another file extension, and the manifest file added first) and are executed using "java -jar jarfile" or "javaw -jar jarfile" command.
I've placed this batch where the jar file is located ("C:\Program Files (x86)\Arachnophilia").
I've also used the default path to "javaw.exe"; if you have installed java to another path (like me) then you have to change it.


penpen

Edit: Added "/d ...".
Edit 2: Changed the first %1 to '%~1' and the second one to "%~1".

genestoy
Posts: 6
Joined: 07 Oct 2016 10:08

Re: Need batch file help please

#7 Post by genestoy » 08 Oct 2016 08:00

penpen,

Thanks for your help, it is really appreciated. The java location on my computer is in the Program Files (x86) so I changed that in the bat file. I placed the bat file in the Arachnophilia folder. I am almost there with your batch file. Here is what happens - windows throws an error if I double click on any html file anywhere on my computer. If I put the bat file on the desktop and drag and drop the file onto it windows throws the same type of error, something about it can't find the file. If I copy and paste the html file to the desktop then double clicking the html file on the desktop the bat works just fine, opens the program and opens the html file in the program. Now if I/We can just get it to open anywhere with a double click, problem solved. Any further suggestions?
Gene

Did some further testing - double clicking on any html file located in a "Parent" folder on the "c" drive the bat works just fine, if the html file is in any folder inside of the "Parent" folder it fails? C:\My Folder\test.html works fine - C:\My Folder\Test Folder\test.html fails - C:\My Folder\Test Folder\3rd Test Folder\test.html fails and so on

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Changing associations for a JAR file to run an editor

#8 Post by penpen » 08 Oct 2016 13:04

I tried to get the same error than you, but failed (for many reasons), until i notioced, that it doesn't work, if the path contains spaces.
I don't know why "C:\My Folder\test.html" worked for you, but i hope the above fix will also work for you.

Reason of the bug (i've found):
If %1 contains spaces and is itself encapsulated in doublequotes then this paramteter breaks a string and creates another token in commandline, which is interpreted as executable (i misuse quote block):
start "text "C:\my path\file.html"" "executable" params.

Also if %1 contains spaces but is not encapsulated in doublequotes, then the last parameter is interpreted wrong.


penpen

genestoy
Posts: 6
Joined: 07 Oct 2016 10:08

Re: Changing associations for a JAR file to run an editor

#9 Post by genestoy » 08 Oct 2016 13:11

Nope, back to square one with the revised code, throws immediate error same as before. The "My Folder" was just a quick name I made up, you are correct it did not work with a space in the folder name
Gene
Last edited by genestoy on 08 Oct 2016 13:39, edited 1 time in total.

genestoy
Posts: 6
Joined: 07 Oct 2016 10:08

Re: Changing associations for a JAR file to run an editor

#10 Post by genestoy » 08 Oct 2016 13:23

Sorry, works perfect!!! I forgot to change the path to the java - Program Files (x86)
THANK YOU!!!!
Gene

Post Reply