Help - Search - Members - Calendar
Full Version: Java Classpath Problem
BleepingComputer.com > Software > Programming
   
ussr1943
hello again all smile.gif
i have decided to learn java.i went to the library got some books and i am on my way learning. wow this is a very useful language and i can't wait to start in. i needed to dl JDK which contains javac, the compiler program(just to run things off my machine first to learn the basics) and java which is the program that executes the .class file the javac compiler created. i have learned u must use the cmd prompt, and i am now at a loss. i have no clue about how to use it, but i tried a few times to do what this book says to run both apps.
it says C:\>javac Example.java
then C:\>java Example
..................................................
well thats all fine and dandy but when i start up cmd prompt it says immeadiately
C:\Documents and Settings\user>
... but i try anyways so i do this
C:\Documents and Settings\user>javac Example.java
and the window says 'javac is not recognized as an internal or an external command, operable program or batch file. i have no clue what to do now, and i have been playing with it for about 2 hours. any help would be appreciated.
thanks]



*crap now that i thought of it, i probably shouldda put this in the programming section*
groovicus
Allow me to move it for you. smile.gif

You are having a classic classpath issue... the software is installed, but the computer does not know that it is installed (if that makes sense). You need to add javac and java to your classpath. Adding it to your classpath is pretty easy, as long as you know where everything is... in other words, you need to know where javac and java are. They are going to be in your jdk/bin folder, so you will need to use explorer to figure out which jdk you downloaded. On my system, the path is C:\jdk1.5.0_06\bin.


Setting Paths:
If running XP, right click on my computer, then select properties. From there, click on the advanced tab, then environment variables. Just under the top text field, click on New. In the variable name, type in JAVA_HOME. In the Value, type in C:\jdk1.5.0_06, except use whichever jdk version that you installed on your system. Then click OK.

Now click on PATH in the top text field, and highlight PATH, then select edit. Add the following at the beginning (sometimes it will not work properly unless this is added first);%JAVA_HOME%\bin;. If there is already something on the path, make sure that there are no spaces following the semi-colon of the entry you just trped in, and the first character of the next entry. For instance:
%JAVA_HOME%\bin;%NETBEANS......
If there are any spaces, it will choke. Once you are done, click OK, then exit.

Open your command prompt, and type in java /?. If you have done this correctly, it should give you a list of commands. IF not, then there is an error in one of the path variables you entered. If it works for java, then try it with javac /?. It should also return a list of commands. Actually, if it works for one, it will work for the other since they are both in the same directory.

Let me know how that goes.
ussr1943
"Now click on PATH in the top text field, and highlight PATH, then select edit. Add the following at the beginning (sometimes it will not work properly unless this is added first);%JAVA_HOME%\bin;. If there is already something on the path, make sure that there are no spaces following the semi-colon of the entry you just trped in, and the first character of the next entry. For instance:
%JAVA_HOME%\bin;%NETBEANS......
If there are any spaces, it will choke. Once you are done, click OK, then exit."
i'm at a loss, i donot see where it says path in the top text field.
groovicus
Are you using Windows XP?

EDIT: Actually, it doesn't matter. I will assume that since you did not find a path variable, then one has not been created. So instead, you would create a new variable named PATH. So just under the first text box, click new, then type in PATH for the variable name.Then in the value box, enter %JAVA_HOME%\bin;.

That should do it.
ussr1943
yes i have windows xp, and i did the first part of what u said but the next part i cant find where it says path where u said.
groovicus
lol.. I just edited my previous post.....
ussr1943
not wuite working, when i do the cmd for java it comes up with stuuf
but not for javac
i did what u said in last post.

have to go eat i will be back in a lil bit.
groovicus
Ok, so we are halfway there then. Open explorer and look in the jdk/bin folder. See if javac exists in there.
ussr1943
yep it exists and is in the right folder.
groovicus
What message are you gettting when you type in javac /?.
ussr1943
'javac is not recognized as an internal or an external command, operable program or batch file
groovicus
What is the full path name to your JDK/bin folder?
ussr1943
C:\Program Files\Java\jdk1.5.0_05\bin
groovicus
Ok, so when you set you JAVA_HOME variable, did you set it to C:\Program Files\Java\jdk1.5.0_05\bin?
ussr1943
yep

****

ok i think i found the problem and its fixed, i noticed for the PATH variable it said C:\Program Files\Java\jdk1.5.0_05\bin\bin
so i got rid of the bin on %JAVA_HOME%\bin;
to makes %JAVA_HOME%
and it shows the path now as C:\Program Files\Java\jdk1.5.0_05\bin
and i typed in both java and javac and they both work now. thanks for your help.




**Mod edit** combined posts~g
groovicus
No problem. Getting the classpath set is one of the hardest things to understand at first, and one of the least explained problems to fix. smile.gif

Happy coding.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.