"java <nameoffile> vs <nameoffile.class>

Exception in thread "main" java.lang.NoClassDefFoundError: nameoffile/cl

***

I have the PATH set so I can use javac and java anywhere. I just need to make sure the CMD is in the same location as the source and class files. I don't understand why when I have the PATH and CMD in the right directory, it gives the error when I put the .class at the end. I enter the first 2 letters or so and hit tab. It then auto completes the file for me with the .cass at the end. The fix is obviously just delete the .class

What is the reason for this though? Is that the standard? Have the prompt auto complete it and delete the .class every time? Is there a alternate way? It seems annoying as I compile most examples. I'm sure most people don't deal with this. Sorry for being newbie :P

[802 byte] By [WOPa] at [2007-11-27 9:22:51]
# 1

When you compile java file(s) you have to specify the files you are compiling. The actual name of the file; extension and alljavac HelloWorld.javaBut when you are running a java program you must give the name of the class whose main method you want to invoke. The fact that there is a file (HelloWorld.class) is not relevant. The java tool requires the name of the class:java HelloWorld

[Edit]I've just checked and on my command line typing tab autocompletes sans ".class". Clever bash.

pbrockway2a at 2007-7-12 22:17:34 > top of Java-index,Java Essentials,New To Java...
# 2

> [Edit]I've just checked and on my command line typing

> tab autocompletes sans ".class". Clever bash.

I think that's because you now have, in that directory, multiple files starting with the same string. So if you have compile HelloWorld.java, you end up with HelloWorld.java and HelloWorld.class in the same directory, so using tab autocompletes to the longest common string, "HelloWorld." (note the period), unless, say, you had some nested classes, in which you might have, say, "HelloWorld$1.class" as well, in which case the longest string is simply "HelloWorld".

It's not that bash knows what kinds of tokens that you need to pass to the JVM.

But I'd be delighted to be proven wrong.

paulcwa at 2007-7-12 22:17:34 > top of Java-index,Java Essentials,New To Java...
# 3

> But I'd be delighted to be proven wrong.

Well I didn't expect it, and don't really understand it: but this is what I seepbrockway@linuxdeskd6off:~/Desktop$ ls Da*

DateEvent.class

pbrockway@linuxdeskd6off:~/Desktop$ javac Da (1)

pbrockway@linuxdeskd6off:~/Desktop$ java Da(2)If I type "tab" at (1) it beeps. If I type "tab" at (2) I getpbrockway@linuxdeskd6off:~/Desktop$ java DateEventI don't know how far this sensitivity extends, but I notice that "cd xx<tab>" autocompletes to a directory name (ends with /), "chmod xx<tab>" autocompletes to a filename and "chown xx<tab>" to a username.

Other application's extensions also seem to be recognised. "gunzip" ignores anything doesn't end with ".gz" when it autocompletes. "gzip" on the other hand ignores anything that *does* end in ".gz".

pbrockway2a at 2007-7-12 22:17:34 > top of Java-index,Java Essentials,New To Java...
# 4
You are actually talking to the shell, it does perform the magical file-name-completion.
BIJ001a at 2007-7-12 22:17:34 > top of Java-index,Java Essentials,New To Java...
# 5
Full details are in the bash manual (surprisingly). Under "Programmable Completion". The exact behaviour when the tab key is pressed is highly configurable via the "complete" builtin command.
pbrockway2a at 2007-7-12 22:17:35 > top of Java-index,Java Essentials,New To Java...