Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Newbie deploymnet question: How to invoke correct JVM?

Posted on 2004-09-03
17
Medium Priority
?
214 Views
Last Modified: 2010-03-31
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


0
Comment
Question by:BrianMc1958
  • 10
  • 7
17 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11974493
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11974507
set path=<different jvm path>;%PATH%

for that particular console
0
 

Author Comment

by:BrianMc1958
ID: 11974570
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 11974588
I don't get the thing about the batch file. What's in it?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11974666
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
 

Author Comment

by:BrianMc1958
ID: 11975370
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 11975454
>>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
 

Author Comment

by:BrianMc1958
ID: 11975821
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
 

Author Comment

by:BrianMc1958
ID: 11975956
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
 

Author Comment

by:BrianMc1958
ID: 11975965
CEHJ--

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

--BrianMc1958
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11975971
Is that problem solved then?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11975993
You might try, simply, in the batch file

@echo off
.\java.exe %*
0
 

Author Comment

by:BrianMc1958
ID: 11976252
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11976433
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11976468
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
 

Author Comment

by:BrianMc1958
ID: 11976569
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11976674
>>Is it possible to give any more points on a "closed" question?

It would be, but don't worry, that's enough ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question