Forum Stats

  • 3,826,761 Users
  • 2,260,705 Discussions
  • 7,897,072 Comments

Discussions

Path / Classpath

Robert Angel
Robert Angel Member Posts: 4,535 Bronze Crown
edited Apr 6, 2018 6:45AM in New To Java

Hi,

I recently started with java, though I have a fairly long career with programming, so I am more than a hobbyist but less than a java pro.

On a p.c. I added the JDK bin location to the system path variable, with my JDK set up in the fairly conventional location C:\Program Files\Java\jdk1.8.0_144

After a reboot I then found that from my c:\java\WorkInProgress directory and others under it I could just javac (etc) without pointing at the jdk bin in any other way - in short I was happy that I had understood enough to get it to work

Recently I bought a new laptop and replicated what I had done before, if it works once it should work again, right?!

Wrong....

I can echo path and see my entry, fine.

But, trying to use the basic java commands in my parallel set up c:\java\WorkInProgress directory does not work.

So two questions; one, am I setting the path correctly, is it more fluke that it worked on the original p.c. is there likely another setting that I am missing.

I was originally following; - https://www.javatpoint.com/how-to-set-path-in-java

Which I have found a very good site for basic examples.

I have tried with user variable and system variable.

I have restarted my laptop after changing before retesting.

It is Windows 10 - which I already dislike intensely

I have googled this but no two pieces of advice seem to be the same on this, so if anyone can point me at the definitive correct way to do it I would appreciate it greatly!!

Best Answer

  • Srini+K
    Srini+K Member Posts: 253 Blue Ribbon
    edited Mar 29, 2018 9:36AM Answer ✓

    doubts are good.. but there are few basics for java.

    1. system need to find the path where java executables are located. ... you need to add them to your %PATH% variable. (in your case you do not have this done right (guessing))

         example:   C:\Program Files\Java\jdk1.8.0_144\bin

                           C:\Program Files\Java\jdk1.8.0_144\jre\bin

    2. java needs %JAVA_HOME% variable for finding libraries.

    Robert Angel

Answers

  • Srini+K
    Srini+K Member Posts: 253 Blue Ribbon
    edited Mar 29, 2018 7:46AM

    you may be missing Java_home variable.  setting the PATH variable allows the executable(s) work but Java still will have trouble finding where to find other java files..

    try setting java_home operating system variable to C:\Program Files\Java\jdk1.8.0_144 or JRE folder under that.

  • Robert Angel
    Robert Angel Member Posts: 4,535 Bronze Crown
    edited Mar 29, 2018 8:21AM

    Hi, I don't have the laptop in question with me right now to try your suggestion, that will have to wait for this evening but I am dubious that your suggestion will work unless this is something that only applies to newer versions of windows, as when I check on the p.c. where it does work; echo %JAVA_HOME% it is not set there, so why would I need it on one but not the other??

  • Srini+K
    Srini+K Member Posts: 253 Blue Ribbon
    edited Mar 29, 2018 9:36AM Answer ✓

    doubts are good.. but there are few basics for java.

    1. system need to find the path where java executables are located. ... you need to add them to your %PATH% variable. (in your case you do not have this done right (guessing))

         example:   C:\Program Files\Java\jdk1.8.0_144\bin

                           C:\Program Files\Java\jdk1.8.0_144\jre\bin

    2. java needs %JAVA_HOME% variable for finding libraries.

    Robert Angel
  • mNem
    mNem Member Posts: 1,380 Gold Trophy
    edited Mar 29, 2018 11:26AM
    OP wrote:On a p.c. I added the JDK bin location to the system path variable, with my JDK set up in the fairly conventional location C:\Program Files\Java\jdk1.8.0_144After a reboot I then found that from my c:\java\WorkInProgress directory and others under it I could just javac (etc) without pointing at the jdk bin in any other way - in short I was happy that I had understood enough to get it to workRecently I bought a new laptop and replicated what I had done before, if it works once it should work again, right?!Wrong....I can echo path and see my entry, fine.But, trying to use the basic java commands in my parallel set up c:\java\WorkInProgress directory does not work.

    you may want to try the following:

    1. set the PATH environment variable to  "C:\Program Files\Java\jdk1.8.0_144\bin";<other path variables> .... (add double quotes around it).

    then open a window console and try java -version command.

    failing that

    2. move or copy the jdk1.8.0_144 folder and its contents to c:\java folder and open a window console

    c:\java\workinprogress>set path=c:\java\jdk1.8.0_144\bin;%path%

    c:\java\workinprogress>javac

    Robert Angel
  • Srini+K
    Srini+K Member Posts: 253 Blue Ribbon
    edited Mar 29, 2018 1:27PM

    not sure I understand the necessity to copy/move jdk folder and contents to C:\java.  can you expand on that..?

  • Robert Angel
    Robert Angel Member Posts: 4,535 Bronze Crown
    edited Apr 6, 2018 6:45AM

    Thanks that resolved it for me.

    Thanks to all with constructive comments.

This discussion has been closed.