|
 |
|
 |
 |
|
02-02-2007, 12:15 PM
|
#1 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
javac command doesnt work
hello,
I am new in java and I was reading this book, every thing was going well untill it was time to compile the program from the word proccesor.
The javac command doesnt work. I do have the latest version of jdk and when I type the (java -version) command, it does show me the version. But when its time to use the compile command, it just doesnt work. I get this: ('javac' is not recognised as an internal or external command, operable program or batch file.)
PLEASE HELP ME, I stopped reading the book because there is no point of reading it when I cant even compile a program 
__________________
|
|
|
02-03-2007, 04:51 AM
|
#2 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
It's not in your PATH. The reason you can run "java" is because Windows installs the JRE by default, and so it's already available to you - you need to point Windows to the new install.
First find out where the copy you downloaded installed to. Usually it's in "C:\Program Files\Java". For instance, I have a copy of 1.5 on my machine, and it's installed in "C:\Program Files\Java\jdk1.5.0_06". Underneath that directory there is a "bin" directory. That is where Java keeps it's commands like "java" and "javac".
Next, right click on My Computer, go to Properties, click on the Advanced tab, and click on the Environmental Variables button. In the System Variables section, modify the "Path" variable to include that "bin" directory from before.
Also, to save yourself headaches in the future, make sure the CLASSPATH variable exists and includes ".", a period. It might contain other things, but make sure it contains that period, otherwise you'll have problems running your java programs.
|
|
|
02-03-2007, 08:18 AM
|
#3 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
the bin diretory is included from the beggining.
I ddnt understand the last part of what you were saying.
Any ways, it still doesn't work. Any sudjestions?
__________________
|
|
|
02-03-2007, 08:36 AM
|
#4 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
The problem is that the "javac.exe" command isn't in the PATH. That's the reason you're getting that error message - it's not a problem with Java, per se, but a configuration problem with Windows. In some form or fashion, Windows can't find the command "javac". It will search through all the directories in the PATH variable to look for it, but if it can't find it, it will return the error message you are getting.
I'm sorry I can't be more helpful, but that is the immediate cause of your problems - the fact that "javac" isn't in any of the directories listed in the PATH variable. The only other thing I can think of is you might have a User variable that's over-riding the system variable, you can check that (it's located along with the System Variables box I described earlier).
|
|
|
02-04-2007, 02:37 AM
|
#5 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
Thnx. It finally worked. But now I have another problem.
When I want to start the program using the (java) command, it doesn't work. I get this: (Exeption in thread "main" java.lang.NoClassDefFoundError: command).
I think what that basically means is that there isn't a class file in the folder which there is after compiling a program.
So, what should I do? Does it have to do with the path again?
__________________
|
|
|
02-04-2007, 05:18 AM
|
#6 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
No, it has to do with the CLASSPATH. Java can't find the class for the program you're calling. My guess is that you don't have ".", or what's known as the "working directory", in your CLASSPATH.
|
|
|
02-04-2007, 12:01 PM
|
#7 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
oow. Where can I find CLASSPATH. Is it the same place where the path is? because if it is, then it isn't there.
__________________
|
|
|
02-04-2007, 12:47 PM
|
#8 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
Yes, and you need to put it there.
|
|
|
02-09-2007, 10:26 AM
|
#9 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
How do I put the CLASSPATH there? details please.
__________________
|
|
|
02-09-2007, 11:02 AM
|
#10 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Follow the advice Belisarius gives in #2, and bellow the "System variable" settings theres a "New" button, click that and add the CLASSPATH as variable -name, and "." as the value.
|
|
|
02-09-2007, 12:52 PM
|
#11 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
ow, ok. But I tryed doing that and nothing happened. the java command still doesn't work. Any ideas?
__________________
|
|
|
02-09-2007, 03:37 PM
|
#12 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
The java command is working fine, it's just a matter of debugging.
Have you created your class file as a package? That is, at the top of the file, did you say "package <some name>"?
Also, did you include a "main" method in your file? That is, is there a method that says:
Code:
static public void main(String[] args) {
.
.
.
}
Something to that effect?
|
|
|
02-10-2007, 09:18 AM
|
#13 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 13
|
I did include a "main" method but how do I creat my class file as a package?
__________________
|
|
|
02-10-2007, 10:49 AM
|
#14 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
In your class file:
Code:
package mypackage.whatever;
...
public class something {
....
...
}
And in your main .java file:
Code:
import mypackage.whatever.*;
public class someClass extends anotherClass {
...
...
public static void main(String[] args){
// Something todo in main...
}
}
|
|
|
02-10-2007, 03:51 PM
|
#15 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
Well, in this case, I was worried that virus had packaged them, and was calling the file incorrectly. That's not the case, so don't worry about it.
Please post both the source code of the file you're attempting to run, as well as the command you entered and the output.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 06:47 AM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|