Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

finding java so I can run java -jar xxx.jar in a batch file  RSS feed

 
Jon Swanson
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created an executable jar file for someone else. So far so good. If he double clicks on the jar file, it runs. But he has a custom icon he wants associated with the jar file. So I tried to provide that as follows-

1. Create a batch file that has the java -jar xxx.jar command in it.

2. Use a program 'bat to exe' that creates an exe from the batch file, allowing me to associate the desired custom icon.

This works on my computer, because java is in my path. Checking a few other people's computers, Java is on the machine, but not in the PATH and JAVA_HOME is not set. So my current thought is the batch file must also find java, put it in PATH and then run java -jar.

I'm wondering if there is standard way in which finding the path to java is done?

I'm a bit reluctant to go the regedit route or run a vbscript to look for appropriate registry keys.

I did find an interesting little command:

dir java.exe /B /S

it starts at the current directory and looks for the file java.exe.

So if I used %Program Files% and %Program Files (x86)% as starting points, I'd probably find java.exe and then could then add it to the PATH. The only problem is that this method is pretty slow, so it takes awhile before the java starts.

there is also the option

where java.exe

to tell me if java.exe is already in the PATH. But, alas, it does not work on XP and only tells me if I need to go looking for java.

I was also thinking I could reliably find java.exe in C:\Windows\System32\ until I looked on a system where it was in C:\Windows\SysWOW64\. I'm not sure how many such places there are, but if these are the only two, checking for these would be faster than running the dir command.

I'm wondering if anyone else has had this problem and has a better solution than what I have found so far?

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a few more questions to add
1.) What if the user has multiple java versions installed but has set one in the PATH, surely that one should be given precedence?
2.) What is the user is not running Windows?
3.) What if the user's computer doesn't have Java at all?
 
Aleksey Vladimirovich
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this, but it'll be platform dependant solution...
You may want to check this topic out: click
There is a solution for you in the last post, but to be frank, you'd better try to convince the guy that it's a bad idea.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch Aleksey Vladimirovich
 
Aleksey Vladimirovich
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And welcome to the Ranch Aleksey Vladimirovich

Thanks! It seems like a good place to get an advice, especially for newbies like me
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!