Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compile a java file from anyother folder

 
Ashutosh Singh Jadon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12184
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i am in the c directory, and my file is in c:\slop, this works:

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

 
Ashutosh Singh Jadon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try javac "C:\Documents and Settings\Hello.java"
 
Ashutosh Singh Jadon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:Try javac "C:\Documents and Settings\Hello.java"

Thanks john, I am able to run it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic