6 Replies Latest reply on Apr 6, 2018 10:45 AM by Robert Angel

    Path / Classpath

    Robert Angel

      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!!

        • 1. Re: Path / Classpath
          Srini+K

          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.

          • 2. Re: Path / Classpath
            Robert Angel

            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??

            • 3. Re: Path / Classpath
              Srini+K

              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.

              1 person found this helpful
              • 4. Re: Path / Classpath
                mNem

                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_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.

                 

                 

                 

                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

                1 person found this helpful
                • 5. Re: Path / Classpath
                  Srini+K

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

                  • 6. Re: Path / Classpath
                    Robert Angel

                    Thanks that resolved it for me.

                     

                    Thanks to all with constructive comments.