Solved

Newbie deploymnet question: How to invoke correct JVM?

Posted on 2004-09-03
17
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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 125 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

726 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