Results 1 to 5 of 5
- 03-24-2011, 09:31 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
classpath - when compiler makes use of that?
Hi,
I am learning to set the classpath property. I have a source file say Test.java in the C:\MyLearning\Samples. I have set the environment variable CLASSPATH to C:\MyLearning\Samples. Now am running the Test.java file from the command prompt. The default user directory is shown. Now I tried running the file from there itself giving "javac Test.java".Its not working. But when am pointing to the same direcory where the source is,and then running the program,it works.Why this is so?The concept of classpath is once we set it,we can run the program from anywhere right?If my source is in d: drive,and I want run it from c: drive,is there any other option other than pointing to same direcory of d:?If this is the case,what is the purpose of classpath?am not including any additional jars or anything, but a simple program to run,what else needs to be done?
Thanks,
Ann
- 03-24-2011, 09:37 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
classpath designates the locations of already compiled bytecode. To designate the location of the source code use the -s option. See this.
- 03-24-2011, 10:00 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Thank you for your quick reply masijade.
Why should I do that if I have already set the environment variable 'CLASSPATH'.Once I set the env variable to point to my source,I should be able to run it from anywhere right?Why it is needed to go to the source directory and then run the program?If thats the case,what is the purpose of classpath.Please make it clear for me.
Thanks,
Ann
- 03-24-2011, 10:12 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
What did I say? You want to compile files, which means you need to designate where the source is, right? And what did I say the classpath designates? The location of the already compiled byte code. What is it you do not understand there?
- 03-24-2011, 10:58 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Also, do not set the environment variable.
It's a bad habit to get into.
If you need to set a classpath then use the -cp switch, or something like ant if it's a hefty project.
Also, when compiling, it's probably an idea to actually compile in the root directory of your project otherwise, as already said, you'll need to set the -s flag as well...which is a bit silly (IMO).
Similar Threads
-
BufferedReader makes me rage
By Onra in forum New To JavaReplies: 3Last Post: 10-24-2010, 06:26 PM -
System ClassPath and compiler question
By Moncleared in forum New To JavaReplies: 1Last Post: 02-23-2010, 03:45 AM -
How does de-serialization makes constructor calls ?
By ajeeb in forum New To JavaReplies: 3Last Post: 03-04-2009, 03:56 PM -
What makes a good programmer?
By cruxblack in forum Forum LobbyReplies: 35Last Post: 11-16-2008, 05:22 AM -
Never makes it to the method!
By minihazard10 in forum New To JavaReplies: 9Last Post: 11-10-2008, 08:30 AM
Bookmarks