• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Run class file error

 
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:


 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the java command, do not include the ".class" extension.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Marshal
Posts: 70228
282
  • 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
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic