DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Using Multiple Versions of JDK and Eclipse in Single Machine

Using Multiple Versions of JDK and Eclipse in Single Machine

Veera Sundar user avatar by
Veera Sundar
·
Aug. 04, 12 · Interview
Like (0)
Save
Tweet
Share
18.67K Views

Join the DZone community and get the full member experience.

Join For Free

In my office laptop, I have installed two versions of JDK. For the office work, I need JDK6 because the internal framework needs it. I’m using JDK7 for my personal projects and exploring the latest and greatest in Java. I have two versions of Eclipse too (one for office work and one is the latest Juno).

But, the tricky thing is to manage these multiple JDKs and IDEs. It’s a piece of cake if I just use Eclipse for compiling my code, because the IDE allows me to configure multiple versions of Java runtime. Unfortunately (or fortunately), I have to use the command line/shell to build my code. So, it is important that I have the right version of JDK present in the PATH and other related environment variables (such as JAVA_HOME).

Manually modifying the environment variables every time I want to switch between JDKs, isn’t a happy task. But, thanks to Windows Powershell, I’m able to write a scriplet that can do the heavy-lifting for me.

Basically, what I want to achieve is to set PATH variable to add Java bin folder and set the JAVA_HOME environment variable and then launch the correct Eclipse IDE. And, I want to do this with a single command. Let’s do it.

  1. Open a Windows Powershell.
  2. I prefer writing custom Windows scripts in my profile file so that it is available to run when ever I open the shell. To edit the  profile, run this command:  notepad.exe $profile - the $profile is a special variable that points to your profile file.
  3. Write the below script in the profile file and save it.
    function myIDE{
    $env:Path += "C:\vraa\java\jdk7\bin;"
    $env:JAVA_HOME = "C:\vraa\java\jdk7"
    C:\vraa\ide\eclipse\eclipse
    set-location C:\vraa\workspace\myproject
    play
    }
    function officeIDE{
    $env:Path += "C:\vraa\java\jdk6\bin;"
    $env:JAVA_HOME = "C:\vraa\java\jdk6"
    C:\office\eclipse\eclipse
    }
  4. Close and restart the Powershell.
  5. Now you can issue the command myIDE which will set the proper PATH and environment variables and then launch the eclipse IDE.

As you can see, there are two functions with different configurations. Just call the function name that you want to launch from the Powershell command line (myIDE or officeIDE).

Java (programming language) Java Development Kit Eclipse Machine

Published at DZone with permission of Veera Sundar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top 10 Secure Coding Practices Every Developer Should Know
  • Load Balancing Pattern
  • How Observability Is Redefining Developer Roles
  • OpenID Connect Flows

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: