aspose file tools*
The moose likes Beginning Java and the fly likes can't we run program like this ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can Watch "can New topic
Author

can't we run program like this ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

i know this is sort of a beginners question but i want to know
when i compile source code like
why so ? can't we run the java program in this way ?


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

do you follow any tutorial for this?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

do you notice the class file location?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

naved momin wrote:
but while running
C:\Users\Admin>java C:Users\Admin\Desktop\FirstApp //it throws an exception ClassDefNotFound Exception

[/code]why so ? can't we run the java program in this way ?


That's not how the JVM finds classes. Assuming FirstApp.class is in C:\Users\Admin\Desktop, you would execute:


java -cp C:\Users\Admin\Desktop FirstApp


That tells the java executable "Run the main() method from the class named 'FirstApp'. The package root(s) in which to search for classes is/are: C:\Users\Admin\Desktop"

In other words, you have to tell the JVM the fully qualified classname to run (including the package, if any). Separately from that, you have to tell it where the roots of package trees are. You can't take pieces off of one and put them onto the other.

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Jeff Verdegan wrote:
naved momin wrote:
but while running
C:\Users\Admin>java C:Users\Admin\Desktop\FirstApp //it throws an exception ClassDefNotFound Exception

[/code]why so ? can't we run the java program in this way ?


That's not how the JVM finds classes. Assuming FirstApp.class is in C:\Users\Admin\Desktop, you would execute:


java -cp C:\Users\Admin\Desktop FirstApp


That tells the java executable "Run the main() method from the class named 'FirstApp'. The package root(s) in which to search for classes is/are: C:\Users\Admin\Desktop"

In other words, you have to tell the JVM the fully qualified classname to run (including the package, if any). Separately from that, you have to tell it where the roots of package trees are. You can't take pieces off of one and put them onto the other.


thanks jeff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't we run program like this ?