• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run class file error

 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run a class file using java command but I got the following error:


 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the java command, do not include the ".class" extension.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or the folder. The way to run a Java application is as follows:
That fully qualified class name means the package name followed by the class name. For example, java.lang.String (of course String has no main method so it won't work, but you get the idea).

You must set the class path (defaults to the current folder only) to be able to run classes located in other folders. The class path should include the root of the package folder structure, not the package folders themselves.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote: . . . You must set the class path . . . to be able to run classes located in other folders. . . .
Don't misunderstand what Rob says. That means you have a different classpath for each application, but most beginners' applications can use the default classpath.

It does not mean you should set a system-side classpath; that usually causes more trouble than it is worth.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I definitely agree. I once put my own libraries in the system wide class path. As a result, one application which used an older version stopped working.
 
feda alshahwan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the answers but how to set the default classpath, What is my classpath?
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't know what the class path is, it's probably only the current directory. As for how to set it, check our FAQ, it's in there somewhere. But as suggested, don't do it. Use the -cp / -classpath JVM flag.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic