Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executing java program whose class file is in diff path

 
jeevanandam palani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
the Sample.class is in Desktop/myclass folder.
i want to execute it from Desktop

what should i do
help me......


 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out URLClassLoader. Don't get the name fool you, you can also represent files as URLs. For instance:
 
jeevanandam palani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in command prompt i want to execute like
java Sample

but classnotfounderror is shown
help me to execute in command prompt..

 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java documentation includes a description on How Classes are Found. The easiest thing would be to include the folder where Sample can be found on the command line, like so:
 
jeevanandam palani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think using classpath option while executing will work,but i dont know how to set the classpath while executing

something like
java -classpath <path> classname

but i don't know how to specify the path,
explanation with example would be even better.
can anyone help me please....
 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jeevanandam palani wrote:but i don't know how to specify the path,
explanation with example would be even better.
can anyone help me please....


Did you even look at what I posted?
 
jeevanandam palani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe Ess,
Your idea is working fine.Thanks for your reply.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems I misunderstood the problem; I thought that you wanted to execute your Java program from another Java program. For your problem the class path is exactly what you need.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic