Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't we run program like this ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you follow any tutorial for this?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you notice the class file location?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic