Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to install multiple JDKs and config the CLASSPTH variable

 
pengpeng lin
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pengpeng lin
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic