This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compile a java file from anyother folder

 
Ashutosh Singh Jadon
Greenhorn
Posts: 18
  • 0
  • 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
  • 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
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic