permaculture playing cards*
The moose likes Beginning Java and the fly likes How to install multiple JDKs and config the CLASSPTH variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to install multiple JDKs and config the CLASSPTH variable" Watch "How to install multiple JDKs and config the CLASSPTH variable" New topic
Author

How to install multiple JDKs and config the CLASSPTH variable

pengpeng lin
Greenhorn

Joined: Dec 24, 2005
Posts: 26
Dear All,

I have to install multiple JDKs in my computer:jdk1.4 & jdk1.5,and not sure that whether there will be a confused situation in my develop environment.Especailly the CLASSPATH's configuration.

How to make sure the compiler will find the right CLASSPATH ?
Should I create a new variable point to the new JDK's lib?
How to choose the JRE in Eclipse?

Thanks all !
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Installing different versions is no problem, as long as you set CLASSPATH, JAVA_HOME and the PATH to the correct version.
In Eclipse, it's just a matter of telling your IDE which one to choose. In the settings, check the Java/Installed JRE's options. You can add JREs you have installed.
You can then choose which JRE to use for each project. Go to the project properties, Java Build Path, Libraries, JRE System Libraries, click Edit and choose the appropriate JRE.
It's not very detailed but I hope you'll figure it out


[My Blog]
All roads lead to JavaRanch
pengpeng lin
Greenhorn

Joined: Dec 24, 2005
Posts: 26
Originally posted by Satou kurinosuke:
Installing different versions is no problem, as long as you set CLASSPATH, JAVA_HOME and the PATH to the correct version.


thanks Satou! Could you explain how to set JAVA_HOME CLASSPATH correctly?For example, I have install jdk1.4 and set the JAVA_HOME CLASSPATH,if I install the jdk1.5
pengpeng lin
Greenhorn

Joined: Dec 24, 2005
Posts: 26
Let's suppose that I have installed the JDK1.4 and set the proper JAVA_HOME and CLASSPATH.If I want to install and config the JDK1.5,how should I do ?

By ceating a new system variable called like 'JAVA_HOME_JDK1.5' and point to the JDK1.5 directory,also like the CLASSPATH.

Or by adding a new string represent the JAVA_HOME and CLASSPATH of jdk1.5 to the existent system variable?

Could you guide me to solve this problem?

Thanks very much!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Actually, you do not need to set the CLASSPATH and JAVA_HOME environment variables at all.

If you don't set the CLASSPATH, then Java will automatically look in the current directory for class files. You can also specify the classpath on the command line when you run a Java program by using the "-classpath" or "-cp" switch, for example:

java -cp C:\MyProject com.mycompany.MyProgram

The environment variable JAVA_HOME is not used at all by the JDK. Some other programs (like Apache Tomcat) use it to determine the location of the Java runtime environment, but it is not really necessary.

Setting the PATH is optional, this is to tell your operating system where it should look for java.exe. If you don't add the "bin" directory your Java runtime environment to the PATH, you can still run Java programs, you'll just have to type in the full path of java.exe, for example:

C:\Java\jdk1.6.0_01\java -cp C:\MyProject com.mycompany.MyProgram

The JDK installation notes explain how to set PATH on different versions of Windows.

To choose the JRE in Eclipse:

Goto the menu Window / Preferences..., choose Java / Installed JREs. There you can manage the JREs that you want to use with Eclipse and the projects you make in Eclipse. Also see the Eclipse help.
[ June 04, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

There's only one JAVA_HOME, one PATH, and one CLASSPATH.
So you'll have to set them before compiling/running your program.

1. If you're compiling at the command line, it's useful to make a batch file containing the proper SET commands.
For example, to use 1.4, in a batch file called setenv14.bat :
SET JAVA_HOME=c:\j2sdk1.4.2_03
SET PATH=c:\j2sdk1.4.2_03\bin;%PATH%

To use 1.5, in another batch file called setenv15.bat :
SET JAVA_HOME=c:\jdk1.5.0_09
SET PATH=c:\jdk1.5.0_09\bin;%PATH%

Before compiling/running a program, you'll have to call the appropriate batch file.

2. If you're using an IDE like Eclipse, you don't have to care to much about that. Just change the settings in Eclipse as I've written in the previous post, and Eclipse will take care of setting environment variables for you.
You can have one project using 1.4, and one project using 1.5, by setting each project's properties correctly. Check the Java Build Path window in the Project Properties.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Satou, I like your approach. I have a couple batch files to switch my command line environment between versions.

For regular "production" use, I launch applications from batch files that set up path & classpath and then run java. Sometimes they get a bit longish. This one runs "stealthy" with no console output ...


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to install multiple JDKs and config the CLASSPTH variable
 
Similar Threads
Installation of Java in Linux
multiple JREs & security provider
How to get multiple version of JDK running
Multiple JREs and java.security
JRE / JDK in parallel?