aspose file tools*
The moose likes Beginning Java and the fly likes How to compile a java file from anyother folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to compile a java file from anyother folder" Watch "How to compile a java file from anyother folder" New topic
Author

How to compile a java file from anyother folder

Ashutosh Singh Jadon
Greenhorn

Joined: Sep 14, 2011
Posts: 18
Hello, This is my first post so forgive me for mistakes.
How to compile a java file on command prompt where command is given from folder in which java file is not reside.


Thanks and regards,
Ashutosh Singh Jadon|SCJP 6.0|
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Ashutosh,
Welcome to the Ranch.

You have to specify the class path option in the java command.

java -cp C:/MyClass HelloWorld.java

where C:/MyClass is the folder where your class files reside.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11295
    
  16

if i am in the c directory, and my file is in c:\slop, this works:

C:\>javac c:\slop\TwinprimeNum.java


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ashutosh Singh Jadon
Greenhorn

Joined: Sep 14, 2011
Posts: 18
John Jai wrote:Hi Ashutosh,
Welcome to the Ranch.

You have to specify the class path option in the java command.

java -cp C:/MyClass HelloWorld.java

where C:/MyClass is the folder where your class files reside.


Thanks for your suggestion. I am able to compile and run also .
However i want to share the problem which i was suffering is that in class path their is a space between the folders like
javac C:\Documents and Settings\Hello.java
Ashutosh Singh Jadon
Greenhorn

Joined: Sep 14, 2011
Posts: 18
fred rosenberger wrote:if i am in the c directory, and my file is in c:\slop, this works:

C:\>javac c:\slop\TwinprimeNum.java

Thanks for your suggestion. I am able to compile and run also .
However i want to share the problem which i was suffering is that in class path their is a space between the folders like
javac C:\Documents and Settings\Hello.java
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Try javac "C:\Documents and Settings\Hello.java"
Ashutosh Singh Jadon
Greenhorn

Joined: Sep 14, 2011
Posts: 18
John Jai wrote:Try javac "C:\Documents and Settings\Hello.java"

Thanks john, I am able to run it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to compile a java file from anyother folder