Deprecated: Assigning the return value of new by reference is deprecated in /home/techmasa/public_html/wp-content/plugins/sem-cosmos-link/sem-cosmos-link.php on line 90

Deprecated: Assigning the return value of new by reference is deprecated in /home/techmasa/public_html/wp-content/plugins/sem-recent-posts.php on line 942

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/techmasa/public_html/wp-content/plugins/sem-cosmos-link/sem-cosmos-link.php:90) in /home/techmasa/public_html/wp-content/plugins/wordpress-automatic-upgrade/wordpress-automatic-upgrade.php on line 121

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/techmasa/public_html/wp-content/plugins/sem-cosmos-link/sem-cosmos-link.php:90) in /home/techmasa/public_html/wp-content/plugins/wordpress-automatic-upgrade/wordpress-automatic-upgrade.php on line 121
TechMasala - Technology Spice Rack » Programming Tip #6 - Using multiple JDK versions

Programming Tip #6 - Using multiple JDK versions

As JDK versions keep coming one in every year, it is difficult to keep track of what runs in which version and you might want to switch between version to execute applications, to learn the newer features of the current version and so on. It is possible to install different versions of JDK in the same box. But every time you go to your command prompt, whatever java path settings you might have set in your environment variable will what be reflected. And if you want to switch to another version you have to change the value of the PATH environment variable to point to the version you want.

Here is a neat way to have a shortcut to get into the command prompt for every jdk version you have in your system.

  • Open Notepad
  • Key in the following

@echo off
set JAVA_HOME=c:\jdk1.5;
set PATH=c:\jdk1.5\bin;
set CLASSPATH=c:\java-jars\junit.jar;c:\java-jars\j2ee.jar;

  • Save the file as say tiger.bat under the folder say c:\
  • Now right click on your desktop and select New->Shortcut
  • In the program location, enter the following

cmd /k c:\tiger.bat

  • Click Next and give the shortcut name, say Tiger (JDK1.5)
  • Click Finish
  • Now double click on the shortcut and in the command prompt type the following command

java -version

Got it? You can create a batch file and a shortcut for every JDK you want just by altering the path of the JDK location in the batch file above. So lets go through whats happening here. DOS provides a way of executing commands in batch which means it can parse through a text file and can execute if that line contains a command it understands. Usually this file is saved with an extension “bat”. So in the above batch file, tiger.bat we use the set command to set the environment variables for that session. The first line @echo off says that the cmd program should suppress displaying the command it is executing. Ofcourse it doesnt stop cmd from displaying any command errors or user messages that can be displayed using the echo command.

OK once we have this file ready, we are creating a shortcut to cmd with an argument of this batch file to be executed when the shell is opened. That’s fine but what is the /k doing there? Well whenever you call cmd passing an argument it interprets and takes appropriate action and then quits. The flag /k tells cmd that it should not quit and wait for more inputs at the prompt. Try removing the /k and see the result for yourself.


Deprecated: Function ereg_replace() is deprecated in /home/techmasa/public_html/wp-content/plugins/sociable/sociable.php on line 64
Blink this Programming Tip #6 - Using multiple JDK versions at blinklist.com    Bookmark Programming Tip #6 - Using multiple JDK versions at blogmarks    Bookmark Programming Tip #6 - Using multiple JDK versions at del.icio.us    Digg Programming Tip #6 - Using multiple JDK versions at Digg.com    Fark Programming Tip #6 - Using multiple JDK versions at Fark.com    Bookmark Programming Tip #6 - Using multiple JDK versions at Furl.net    Bookmark Programming Tip #6 - Using multiple JDK versions at NewsVine    Bookmark Programming Tip #6 - Using multiple JDK versions at reddit.com    Bookmark Programming Tip #6 - Using multiple JDK versions at Simpy.com    Bookmark Programming Tip #6 - Using multiple JDK versions at Spurl.net    Bookmark Programming Tip #6 - Using multiple JDK versions with wists    Bookmark Programming Tip #6 - Using multiple JDK versions at YahooMyWeb

      Cosmos

Leave a Comment

authimage


Creative Commons License  This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.