• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Difficulties setting the PATH to JAVA_HOME

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new to using Java programming and am new to this site. I used the following link to assist me in setting the PATH for the Java JDK I downloaded, but when I typed javac in my terminal, I still received this message: 'javac' is not recognized as an internal or external command, operable program or batch file.

The website link I used to assist me was this: https://www.codejava.net/java-core/how-to-set-java-home-environment-variable-on-windows-10

When I typed in the path to the JDK version I downloaded, I typed this: C:\Program Files\Java\jdk14.0.1

I am not sure what other steps need to be taken in order for this to work. Am I using a version of JDK that is too new? Any input would be awesome. Thanks so much.
 
Rancher
Posts: 3795
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The path needs to point to the folder that contains the .exe file.  That is where the OS will look for the .exe file.
For the JDK, the location of the javac.exe file is the bin folder.  So the end of the path should be bin

Read all of the pages at the link you provided.
 
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Amy Ayy wrote:H. . . The website link I used to assist me was this: . . . .

Unfortunately it doesn't assist you at all.. It tells you,

. . .
So the PATH environment variable should include JAVA_HOME:
1 PATH = Other Paths + JAVA_HOME
. . .

...which is wrong. As Norm told you, it should be JAVA_HOME\bin (on a Windows® machine).

Am I using a version of JDK that is too new? . . . .

Each new JDK version creates its own installation folder and therefore has its own JAVA_HOME, so I have never heard of that being a problem.

And . . . welcome to the Ranch
 
Campbell Ritchie
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:. . . Read all of the pages at the link you provided.

It does eventually say to add \bin, but by the time you reach that part, you have already been given misleading information.
 
Saloon Keeper
Posts: 22126
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, JAVA_HOME isn't even an official part of Java. It's just a very common convention.

JAVA_HOME always points to the root of the JDK or JRE that you're going to use it with. That means that you can have multiple versions of Java on a machine and just by setting JAVA_HOME to indicate you want one to use for a particular application. Other applications may use different JAVA_HOMEs and thus different Java versions at the same time, since ultimately each command shell can set its own value of JAVA_HOME independently of the setting of any other JAVA_HOME.

Typically you have a master (default) setting for JAVA_HOME so you only have to change its value in a command shell if you want to override that default.

The Java executables are found at %JAVA_HOME%\bin so that's the value that you add to your PATH.

In Unix-like systems, a login environment will typically have something like this in it:


 
Saloon Keeper
Posts: 7179
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Wlindows there is another gotcha, you have to place %JAVA_HOME%\bin first on the PATH because Oracle was embedding an older link to Java in C:\Windows which normally comes first or early on.
 
lowercase baba
Posts: 12856
52
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't see this mentioned, but once a cmd window is open, the environment variable for THAT window are set.  there probably are ways to update it within an open window, but it's probably easier to close the current one and open a new.
 
Tim Holloway
Saloon Keeper
Posts: 22126
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use the SET command.
 
Ranch Hand
Posts: 127
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:On Wlindows there is another gotcha, you have to place %JAVA_HOME%\bin first on the PATH because Oracle was embedding an older link to Java in C:\Windows which normally comes first or early on.


Although this tip is a good idea to your explanation why isn't quite correct and only applies when there's more than exactly one runtime installed, and even then only because an older version may is silently updated in the background.
If one makes sure to not have another runtime installed it doesn't matter where on the path it appears.
If you suffer from the said problem the correct way of fixing it would be to remove any other runtime than the one you intent to use instead of try to override by specific ordering of PATH.
 
Campbell Ritchie
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That might work if we were aware of all the different JREs installed. Some might be installed with something else without the user noticing. Also, one might actually want multiple runtimes, so one can try different versions readily by changing the PATH temporarily
 
Tim Holloway
Saloon Keeper
Posts: 22126
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:so one can try different versions readily by changing the PATH temporarily



Been there/did that. Quite often, actually.
 
Norm Radder
Rancher
Posts: 3795
35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And then you can always use the full path to the exe file and not rely on the OS's PATH environment variable.  My "IDE" has several tools that can be loaded with the path to the file to be used for compiles and executions.
Also batch files can be used.  Or on Windows the registry can be loaded with command-lines.
 
Marshal
Posts: 25594
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words: As far as Java is concerned, the PATH environment variable is a horrible mess. And the tutorial you were using was unfortunately not the best one to use.

It used to be (up until Java 8) that Oracle would provide you with a Windows installer, which would install the JDK and JRE and also fix up the PATH in a workable way. Now they don't do that any more and the poor beginner is thrown into the deep end of the swamp.
 
Tim Holloway
Saloon Keeper
Posts: 22126
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:In other words: As far as Java is concerned, the PATH environment variable is a horrible mess. And the tutorial you were using was unfortunately not the best one to use.

It used to be (up until Java 8) that Oracle would provide you with a Windows installer, which would install the JDK and JRE and also fix up the PATH in a workable way. Now they don't do that any more and the poor beginner is thrown into the deep end of the swamp.



PATH is no bigger a mess for Java than for any other Windows app. And as far as installation setting the Windows System/User environment defaults, I don't actually recall it doing that. But there's many ways to install, so I might not have been using the "right" one. Plus, I don't work with Windows that often to keep track of what they're up to over there.

The Oracle installer for Red Hat Linux and similar RPM-installed systems installs all JREs/JDKs to /usr/java and updates /usr/java/latest to be a softlink to the highest version number found while installing. But none of that applies if you install from the general-purpose Linux ZIP file as unzip doesn't/can't run installer scripts. One less means of infecting systems.
 
Carey Brown
Saloon Keeper
Posts: 7179
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

and the poor beginner is thrown into the deep end of the swamp.


And the poor developer trying to distribute a simple app.
 
Bob Winter
Ranch Hand
Posts: 127
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:That might work if we were aware of all the different JREs installed.


Well, that'S quite easy:
As on windows only installers are supposed to modify system wide settings any other "archive extracting" only relies on the linux way of have a config file in its own directory. Also, unless you running 24/7 with an Administrator account only applications with whats called an application manifest are able to request elevation via UAC. So, for a "normal" user it's quite easy to keep track of all "installed" runtimes. And as a developer one should know her/his way around her/his OS before trying to tell it what to do (as that's what's programming is in simple terms).
Said in another way: You should learn how to use a computer before you try to tell it what to do by start learning programming. Not able to correctly keep track of installed applications or the very simple and easy task to set some environment variable often is a sign one lacks some required basic knowledge and should learn those before try to progress any further - but that's just my way of looking at it.

TBH: Yes, I too had to ask how to correctly use Integer.parseInt() - but at the time I asked this question I already knew how acquire and correctly set up a JDK.
 
Tim Holloway
Saloon Keeper
Posts: 22126
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That only works if you used an installer. I'm pretty sure that the Windows version is just like the other OS JDK/JRE versions in that there's a simple ZIP install.

Java does diddle a bit with the registry on Windows, in violation of its general "write-once/run-anywhere" policy, but not in a way that absolutely requires elements to be set in the registry or in files external to the exploded ZIP. So if I download a ZIP-form Windows install file, I can unzip it anywhere I like and it will work just as well and the installation database won't be any the wiser.

Some apps do scan for installed Java runtimes, but they have to do it by brute force, searching the directory tree for bin/java or some other significant file.
 
Amy Ayy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow. Thanks so much for all the replies. I did check that I did not have any older/previous versions of JDK installed in my installed programs, so it must be an issue with setting the PATH using the steps that were outlined in the link I found. I am not sure that I understand fully what I need to do but I am going to keep researching into this and see if I find it. Thanks for all of your input.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make the binary files of certain locations executable form any location of the computer without copying them physically to other locations, we must add the original location of those files to the path variable. Similarly, to use the java tools we need to set the java path.

The path variable is a mediator between the programmer and the command prompt window. The programmer should set the path variable by storing the binary file path (bin folder path). Command prompt need path variable to find and execute binary files of software.

There are two types of setting the path variable to solve the above problem:- temporary settings, and permanent settings.

The temporary settings lost after closing the command prompt window. For every new command prompt window or terminal, we must do this setup again and again.

The permanent settings can be done at two levels, one for a single user and another for all users of one operating system.

Learn More:- Different ways to set the Java path | knowprogram.com
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic