Solved

Newbie deploymnet question: How to invoke correct JVM?

Posted on 2004-09-03
17
202 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

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