Computing.Net > Forums > Programming > running java from command line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

running java from command line

Reply to Message Icon

Name: Joel Deziel
Date: September 30, 2003 at 22:07:51 Pacific
OS: Windows XP
CPU/Ram: P4 1.8 / .75GB RD-RAM
Comment:

I am having trouble running java programs from my command line. I know I have all my paths set up properly. I created a Hello Word program as follows:

public class TestMe {
....public static void main(String args[]) {
........System.out.println("Hello World");
....}
} //dots are for spacing purposes within this msg

I type "javac TestMe.java" and received no compilation errors. Also, a class file was created. I then type "java TestMe" and receive the error:

Exception in thread "main" java.lang.NoClassDefFoundError: TestMe

This is the same error you get if you accidentally type a wrong filename, like: "java TestMeee" and make the JVM look for a file that doesn't exist. I can even open JCreator Pro and run the .class file just fine without recompiling the .java file.

Can anyone please help? Thanks so much!



Sponsored Link
Ads by Google

Response Number 1
Name: gpp
Date: October 1, 2003 at 05:50:26 Pacific
Reply:

You're sure its creating a class file, and that its size is greater than 0? Cause thats an error you would get if the class just doesnt exist...


0

Response Number 2
Name: Joel Deziel
Date: October 1, 2003 at 07:08:50 Pacific
Reply:

The .class file is definitely being created. Its size is greater than 0 bytes.


0

Response Number 3
Name: gpp
Date: October 1, 2003 at 07:33:23 Pacific
Reply:

And the file name is exactly the class name?? It should work.. I dont see anything wrong with your code. try creating a new file with a new name and compile that..


0

Response Number 4
Name: Joel Deziel
Date: October 5, 2003 at 08:50:30 Pacific
Reply:

I've tried starting over many many times, nothing seems to work. I guess I'm just destined to not be able to run java programs from my command line.


0

Response Number 5
Name: vvanherk
Date: October 16, 2003 at 11:20:56 Pacific
Reply:


You need to specify the -classpath specifier. if you are running from current directory where class file is:

java -classpath . myClass


0

Related Posts

See More



Response Number 6
Name: Joel Deziel
Date: October 18, 2003 at 10:14:21 Pacific
Reply:

Wow that actually worked! Thank you so much. But is there a way to make it so the system will always just use my current directory as the classpath? Can I set the environmental variables somehow?


0

Response Number 7
Name: __Ralph__
Date: October 28, 2003 at 15:07:19 Pacific
Reply:

Joel,

For XP (its simlar for all OS's) right Click on your "My Computer" Icon, select "Properties", then "Advanced" then "Environment variables" and add or edit you CLASSPATH variable to include "."

eg mine is:
C:\ralph\classes;.

Now when you run Java programs it should always look in the current directory for classes.

regards
ralph


0

Response Number 8
Name: Joel Deziel
Date: October 29, 2003 at 15:25:02 Pacific
Reply:

Thanks, that worked like a charm.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: running java from command line

kill a process from command line www.computing.net/answers/programming/kill-a-process-from-command-line/14109.html

Help for batch script www.computing.net/answers/programming/help-for-batch-script/9732.html

Running Software from Desktop www.computing.net/answers/programming/running-software-from-desktop/7765.html