This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Run class file error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Run class file error" Watch "Run class file error" New topic
Author

Run class file error

feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
I am trying to run a class file using java command but I got the following error:


marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

When you use the java command, do not include the ".class" extension.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36482
    
  16
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

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

Joined: Jul 26, 2008
Posts: 170
Thank you for the answers but how to set the default classpath, What is my classpath?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Run class file error
 
Similar Threads
Jobfuscate
running with command line
Do I need to reinstall Java?
NoClassDefFoundError
problem on extending a class declared on the same package!!