• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to configure source file  RSS feed

 
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to change path to the source dir on command line to execute a source file.
How can I configure a source file die so that I can run it from anywhere ? I have configured it in PATH variable at this time, but it is not working
e.g. "C:\Users\nm2t\Desktop\JavaTest" is the location where source files are located and I have configured PATH variable as "C:\Users\nm2t\Desktop\JavaTest;" When I run javac, I am getting following error
C:\Users\nm2t\Desktop\JavaTest>cd\

C:\>javac -d "C:\Program Files\Java" JarTest.java
javac: file not found: JarTest.java
Usage: javac <options> <source files>
use -help for a list of possible options
So how to setup source path in environment variable ? Do I setup in CLASSPATH variable ?

Thanks
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PATH has nothing to do with this, and neither has CLASSPATH. If you look at the options of "javac" like the error message said to, you'll see that the "-d" option is not how you specify where to look for source files (which are "compiled", by the way, not "executed"), and it tells you which option you can use instead.
 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-d "C:\Program Files\Java" is the location where I want compiled class file to be stored at.
I can provide C:\Users\nm2t>javac "C:\Users\nm2t\Desktop\JavaTest\JarTest.java" and it compile fine.
But I want to give command as "C:\Users\nm2t>javac JarTest.java" without giving any path.
Is there a way, where I can configure source path "C:\Users\nm2t\Desktop\JavaTest" and compiler will look for this source file automatically like it does for variables set in PATH and CLASSPATH

Thanks
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The javac compiler never uses PATH and setting CLASSPATH is not the right thing to do specify the location of source files.
As Ulf has already said there is a flag that allows you to specify the src dir ie -sourcepath. Alternatively if you don't want to write that out each time, change the current directory to the source directory or put the command in a batch file and execute that.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has our advice helped you to solve this?
 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Your advice did help.
I had to do trial and error to figure this out.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use trial and error; you will never learn like that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!