Solved

Newbie deploymnet question: How to invoke correct JVM?

Posted on 2004-09-03
17
177 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
Comment Utility
>>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
Comment Utility
set path=<different jvm path>;%PATH%

for that particular console
0
 

Author Comment

by:BrianMc1958
Comment Utility
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
 
LVL 86

Expert Comment

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

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:BrianMc1958
Comment Utility
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
Comment Utility
CEHJ--

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

--BrianMc1958
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Is that problem solved then?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You might try, simply, in the batch file

@echo off
.\java.exe %*
0
 

Author Comment

by:BrianMc1958
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now