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
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.
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
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
Summary: Hi, Can some one help me with this? I scheduled a task from Win xp "Scheduled tasks". This job is will open a reflection window( an application for unix) and doing some other jobs. I want to run it da...
Summary: Thanks wizerd-fred. Here is what I want: I have a file1.txt like this: "0003 0004" Also I have a batch command like this: for /f %f in (c:\dir1\file1.txt) do @echo SS02%f && isql -i"c:\dir1\file2.sq...
Summary: Hi all, Is there a way to run completed java programs from the desktop by clicking a desktop icon? I would like to know how to run my finished applications without having to go to the command line ev...