• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How To Set Up Environmental Variables In Java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Java newbie here. I am trying to make my javac compiler work. I believe I have set up my environmental variables properly, but the command prompt still says it does not recognize as an internal or external command. When I enter "where javac" I get "C:\Program Files\Java\jdk1.8.0_45\bin\javac.exe". But when I type in just "javac" I get the it doesn't recognize message. Any help with this would be much appreciated, I have not sarcastically tried doing this 10 to 20 times, watched many YouTube videos, and read many forums as well as posts from Oracle. I seem to be doing everything right but for some reason it still will not work. Thanks for the help.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Did you close and open the command prompt again after setting the environment variables? The Windows command prompt does not immediately pick up changes in the environment variables.

What output does the following command give you: echo %PATH%

Watch out that there are no spaces in the PATH where they should not be. Directories in the PATH must be separated by ; (semi-colon) and you should not put spaces before or after the semi-colons in the PATH. (Some people make the mistake of putting a space after the sem-colon: "...;<space>C:\Program Files\...").
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java is designed so that you can have (and use!) multiple brands/versions of JVM on the same machine at the same time. Unlike certain other vendors products I could mention...

Conventionally, you would want to set the system environment variable JAVA_HOME to have a value of "C:\Program Files\Java\jdk1.8.0_45" and add %JAVA_HOME%\bin to your PATH. That would give you defaults that match what you are looking for.

Oops. I forgot the thing about spaces in path names. If your version of windows supports it, the easiest way to avoid that is to find the 8.3 equivalent name (typically, it's "PROGRA~1") and use that instead of "Program Files". Otherwise the parser stops looking after it hits the space and results in an improper path search.
 
Robert Berry
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the responses.

When I type in echo %PATH% I get this ...;C:\Program Files\Java\jdk1.8.0_45\bin.

I do not believe there are any spaces between semicolons in the path. I have also done as suggested and put %JAVA_HOME%\bin in my path after creating the JAVA_HOME variable and this has not worked either. I have not tried using Program Files as one word or a new word. How should I do that?

Thanks for the help.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I enter "where javac" I get "C:\Program Files\Java\jdk1.8.0_45\bin\javac.exe".



If you get what you did from a "where javc" command, then the problem is NOT in your PATH (assuming there is a file "C:\Program Files\Java\jdk1.8.0_45\bin\javac.exe". Have you checked?)

But when I type in just "javac" I get the it doesn't recognize message.



What exactly is the error message?
 
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

You should move your Java1.8 installation folder to the beginning of the PATH. Otherwise if there is an older version of Java® anywhere else in the PATH, you will end up using a newer version of javac and older version of java, and the older version of java won't like that.
ProgramFiles should not be one word. Try putting "quotes" round the entire PATH string because of the space.
Try this instruction at a new command line:-
set PATH="c:\Program Files\Java\jdk1.8.0_45\bin";%PATH%
and see what happens. That instruction is very useful; it can reset the version of Java® you are using for the lifetime of that command window.
 
Campbell Ritchie
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also try
"c:\Program Files\Java\jdk1.8.0_45\bin\javac" -version
with and without the quotes and see what happens. That instruction includes the entire path to javac and should enable you to find the tool. Also open the Java folder with windows explorer and confirm there is a bin folder with java.exe, javac.exe etc in.
 
Robert Berry
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It finally worked! I have no idea what it took, or why it didn't work the first 20 times, but I finally managed to print out Hello, World! Thanks for all the help!
 
Campbell Ritchie
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic