wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes executing java program whose class file is in diff path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "executing java program whose class file is in diff path" Watch "executing java program whose class file is in diff path" New topic
Author

executing java program whose class file is in diff path

jeevanandam palani
Greenhorn

Joined: Dec 16, 2009
Posts: 5
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

Joined: Oct 27, 2005
Posts: 19723
    
  20

Check out URLClassLoader. Don't get the name fool you, you can also represent files as URLs. For instance:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jeevanandam palani
Greenhorn

Joined: Dec 16, 2009
Posts: 5
in command prompt i want to execute like
java Sample

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

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

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:


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
jeevanandam palani
Greenhorn

Joined: Dec 16, 2009
Posts: 5
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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

Joined: Dec 16, 2009
Posts: 5
Hi Joe Ess,
Your idea is working fine.Thanks for your reply.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

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.
 
Consider Paul's rocket mass heater.
 
subject: executing java program whose class file is in diff path