Newbie deploymnet question: How to invoke correct JVM?

Dear Experts,

My application needs to invoke java.exe on a remote Windows box.  I install "my" version of the JVM on the Windows box, but my application doesn't know where.  It just invokes "java.exe MyClass", with no absolute path.  Therefore, the Windows box uses the PATH environment variable to locate java.exe.  Unfortunately, it's finding an older version, not the one I installed.

I can't specify an absolute path.

I can't add my location to the BEGINNING of the PATH variable, as that would interfere with other software.  Adding at the END doesn't help.

I don't really know enough to use the registry.

I had one idea, but I'm having trouble implementing it.  Instead of directly invoking java.exe, I was going to invoke a .bat file called something like CALL_MY_JAVA.bat, which would then invoke the java.exe located in the same directory as it is.  I could add this directory to the END of the PATH variable on the Windows box, which would then find it OK because it would (probably) be the only file with that name.

However, I'm having two problems with this.  First, I can't get the .bat file to return it's own location, so I could use CD to change the current directory to it's own.  Second, the whole thing sounds like a hack.  
 
I'm sure this is a standard problem.  What's the solution, Experts?

Thanks in advance,
BrianMc1958


BrianMc1958Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
>>I can name it something unique, so when I add it to the PATH on the Windows box

>>The batch file can then invoke the java.exe that lives in the same directory as it does

I'm still puzzled - if you know the path to the batch file (and you'll have to in order to add it to your PATH) then you'll know the path to the java.exe you want, won't you?

0
 
CEHJCommented:
>>I can't specify an absolute path.

Why not?

>>I can't add my location to the BEGINNING of the PATH variable, as that would interfere with other software

You don't need to set it permanently - just fro that console process
0
 
CEHJCommented:
set path=<different jvm path>;%PATH%

for that particular console
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
BrianMc1958Author Commented:
I don't KNOW the absolute path.  I know I can temporarily add to the PATH, but I don't know what to add. That's why I'm trying to get the batch file to return it's own location...
0
 
CEHJCommented:
I don't get the thing about the batch file. What's in it?
0
 
CEHJCommented:
i.e. how is a batch file going to help? - you'll still need to know the right path. I don't think there's a way of doing this without the path
0
 
BrianMc1958Author Commented:
Sorry.

The batch file has two purposes.

1.  I can name it something unique, so when I add it to the PATH on the Windows box, I can later find it unambiguously.  (There might be lots of java.exe's in the PATH, but only one CALL_MY_JAVA.bat).

2.  The batch file can then invoke the java.exe that lives in the same directory as it does.

So the batch file would basically act as a marker, telling me I've found the directory where MY java.exe lives.  Then, as a bonus, it would invoke that java.exe.

It doesn't have to be a batch file.  Any program that could put it's own location into a string, and then use that string to invoke java.exe in it's own directory would work.

Like I say, though, I haven't been able to get a batch file to return it's own location yet.  And I'm looking for a more "industry-standard" solution from the Experts...
0
 
BrianMc1958Author Commented:
Sorry again...

Maybe more detail will make things more clear.

I use InstallShield to install everything on the Windows box.  It installs to whatever drive the Programs Directory is on.  InstallShield then adds that directory to the PATH environment variable on the Windows box.  This all happens at my customer sites.  I don't know where things will be installed to beforehand.

My calling application, which lives on another box, doesn't know where anything was installed on the Windows box.  It just knows there's something called "java.exe" there.  So it just calls "java.exe" on the Windows box.  The Windows box then searches the PATH environment variable and runs the FIRST OCCURENCE of java.exe it finds.  Unfortunately, there are often many java.exe's within the PATH, so it doesn't find the one I want.

Therefore, I thought I also install on the Windows box a simple batch file WITH A FUNNY NAME, that would not appear anywhere else on the Windows box.  So instead of telling the Windows box to look in PATH for java.exe, it would look for something called CALL_MY_JAVA.bat (or CALL_MY_UNIQUELY_NAMED_*#DTYEF^RYFVJDHG&REIUY.bat).  My calling application STILL wouldn't know WHERE the called application was, but it could then depend on the PATH variable on the Windows box to find it unambiguously.

Then, I just need some way for the batch program to find out where IT ITSELF is located, because it will be located in the same directory as the java.exe I want to use.  (This is the part I haven't figured out yet.)  Once it has that as a string (something like "C:\Program Files\My Company\My App\", it can just append "java.exe" to that to make an absolute path.

Is that any more clear?

Thanks again...
0
 
BrianMc1958Author Commented:
CEHJ--

Given that I know it's going to ProgramFiles, I can have .bat return that, and construct my own path.  So I DO know where things are located, like you said...

Thanks for your help.

--BrianMc1958

0
 
BrianMc1958Author Commented:
CEHJ--

But if you still want to respond to my last post, I'd be interested.  

--BrianMc1958
0
 
CEHJCommented:
Is that problem solved then?
0
 
CEHJCommented:
You might try, simply, in the batch file

@echo off
.\java.exe %*
0
 
BrianMc1958Author Commented:
Almost...

I can now return the Program Files as a string ("C:\Program Files") within the .bat.  So I have the absolute path ready.  I just haven't figured how to get it to execute.  This is what I have:

     SET myprog = %programfiles%\My Company\My App\java.exe
     echo %myprog%
     %myprog% helloWorld %1


%myprog% looks OK, but I can't get it to execute helloWorld yet.  I'm a batch dummy...  Any ideas?
0
 
CEHJCommented:
Try

SET myprog="%programfiles%\My Company\My App\java.exe"
echo %myprog%
%myprog% helloWorld %*


although classes should really being with upper case characters of course
0
 
CEHJCommented:
You might have to check with the Windows TAs about execution though, as i'd doubt that the streams of that remote process will be visible on your local console. There may be a way of redirecting the streams though. You may be able to get a remote shell
0
 
BrianMc1958Author Commented:
IT WORKED!  IT WORKED!  IT WORKED!

I'm also a newbie at EE.  Is it possible to give any more points on a "closed" question?

If not, thanks anyway, CEHJ.  Have a nice long weekend!
0
 
CEHJCommented:
>>Is it possible to give any more points on a "closed" question?

It would be, but don't worry, that's enough ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.