Home arrow static arrow Java Programming [Archive] - How to run the java program from another directory?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - How to run the java program from another directory?
This topic has 4 replies on 1 page.

Posts:104
Registered: 12/1/03
How to run the java program from another directory?  
Jul 11, 2004 12:19 AM



 
Hi
Assumption:
data.java is in a package suncertify.db and place in a directory c:/code/suncertify/db/ directory
data.class file: is in c:/code/suncertify/db/ directory
current directory: c:/

How can execute the data.class directly in c:/ directory without changing directory to c:/code/ ?

Thanks in advance,
Adrian
 

Posts:11,200
Registered: 7/22/99
Re: How to run the java program from another directory?  
Jul 11, 2004 12:58 AM (reply 1 of 4)



 
java -cp code suncertify.db.data
 

Posts:104
Registered: 12/1/03
Re: How to run the java program from another directory?  
Jul 11, 2004 11:09 PM (reply 2 of 4)



 
Thanks a lot.
But what about compiling the code? Can I compile the code in c:/ directory without changing to c:/code/ directory?

Thanks in advance,
Adrian
 

Posts:11,200
Registered: 7/22/99
Re: How to run the java program from another directory?  
Jul 12, 2004 12:20 AM (reply 3 of 4)



 
Yes. You can use the -classpath and -sourcepath options to specify where to look for source files, and the -d option to specify where to generate the class files. Look up the usage of those options in the javac documentation:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html
 

Posts:104
Registered: 12/1/03
Re: How to run the java program from another directory?  
Jul 12, 2004 2:28 AM (reply 4 of 4)



 
Great, thx a lot.
 
This topic has 4 replies on 1 page.