Forum Stats

  • 3,828,170 Users
  • 2,260,869 Discussions
  • 7,897,502 Comments

Discussions

How to setup windows environment for compiling Java 8 or 9 source code

OTG-467455
OTG-467455 Member Posts: 506 Bronze Badge
edited Nov 16, 2017 3:23AM in Java Puzzle Ball

I have Java 8 and 9 installed on my desktop and laptop.  Compiling with javac does not work.   Is there any efficient way to configure the system so that I can compile with one or the other version.

Message was edited by: OTG-467455

OTG-467455

Best Answer

  • NickR2600-Oracle
    NickR2600-Oracle Member Posts: 530 Employee
    edited Nov 15, 2017 2:21PM Answer ✓

    I've had to set a few environment variables for windows, which would look something like this depending on where you've installed everything:

    • JAVA_HOME = C:\Program Files\Java\jdk-9.0.1 (or 8 if you prefer)
    • Path = C:\ProgramData\Oracle\Java\javapath;%JAVA_HOME%\bin;

    Does this help?

    OTG-467455OTG-467455

Answers

  • NickR2600-Oracle
    NickR2600-Oracle Member Posts: 530 Employee
    edited Nov 15, 2017 2:21PM Answer ✓

    I've had to set a few environment variables for windows, which would look something like this depending on where you've installed everything:

    • JAVA_HOME = C:\Program Files\Java\jdk-9.0.1 (or 8 if you prefer)
    • Path = C:\ProgramData\Oracle\Java\javapath;%JAVA_HOME%\bin;

    Does this help?

    OTG-467455OTG-467455
  • OTG-467455
    OTG-467455 Member Posts: 506 Bronze Badge
    edited Nov 15, 2017 2:58PM

    I only adjusted the Path environment variable.   Is there no way of having both environments defined and being able to switch between them.

  • mNem
    mNem Member Posts: 1,380 Gold Trophy
    edited Nov 16, 2017 2:42AM

    You may give this a try ...

    1. Create two batch files one for each jdk (say C:\temp\jdk8.bat and C:\temp\jdk9.bat).

    2.  Add entries in each file to set the PATH environment variable (adjust the folder path to your env).

    jdk8.bat

    set PATH=C:\DEV\jdk1.8.0_25\bin;%path%;echo %PATH%

    jdk9.bat

    set PATH=C:\DEV\jdk9\bin;%path%;echo %PATH%

    3. Open up a command window from the source file location.

    4.  Run the bat file, for example if you want to work with jdk9.

    >>c:\temp\jdk9.bat

    5. check for the javac version

    >>where javac
    or
    >>java -version

    6. You can open up another command window and have the jdk8.bat run. and work there with that version side by side.

    7. These settings are local to the opened command window.

    Personally, I think this is too much of a headache to have, unless for learning purposes on how to compile a set of java files from command line.

    I still prefer the comfort of an IDE. You could in this case, create two SEPARATE projects.

    OTG-467455OTG-467455
  • OTG-467455
    OTG-467455 Member Posts: 506 Bronze Badge
    edited Nov 16, 2017 3:23AM

    mNem, Your suggestion is doable, but like you said it is a bit too cumbersome.   Looks like one has to setup one environment or the other.   That is unless the home can be switched like it used to be for oracle databases.