File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Multiple JDK's and JRE's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multiple JDK Watch "Multiple JDK New topic

Multiple JDK's and JRE's

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I have need to run at least two different JDK versions, 1.3.1 and 1.4.
What is the best way to compile code using the two individually without having to be in the JDK's Bin directory, or using an absolute path to that JDK's Bin Directory every time.
I was thinking of using a batch file, but I don't know how I would get the batch file to take in arguments. i.e java1.bat myProgram where java1.bat runs the JAVAC for 1.3.1 and myProgram is the program to be compiled.

GenRocket - Experts at Building Test Data
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
I have several bat files out there.
For instance I have j131.bat, j140.bat etc. When I want to use a particular release, I run the bat that sets up a different path and classpath on the fly.
I just work in the working directory that I set up for each of these.
Then you can just work as normal.
However, If you want to invoke a particular JRE when starting your program (perhaps a different one from what your normal classpath points to) you can just specify when you invoke the application. The actual call to the app is bolded.
example RunAPP.bat:

cd \"Program Files"\app
path = .;C:\"Program Files"\app;C:\"Program Files"\app\jre\bin;
"c:\Program Files\app\jre\bin\javaw" -classpath .;"c:\Program Files\app";"c:\Program Files\app\app.jar";"c:\Program Files\app\deploy.jar";"c:\Program Files\app\jre\lib\rt.jar";"c:\Program Files\app\jre\lib\jaws.jar";"c:\Program Files\app\jre\lib\i18n.jar";"c:\Program Files\app\classes12.jar";"c:\Program Files\app\images" app.client.APPDesktop "c:\Program Files\app\"

"JavaRanch, where the deer and the Certified play" - David O'Meara
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

So instead of running a batch file that runs the compiler, you just set up a batch file that resets your paths to whatever you need them set to. Smart Lady
Thanks Cindy. As always you have solved my problem.
I agree. Here's the link:
subject: Multiple JDK's and JRE's
It's not a secret anymore!