This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes need help in understanding classpath? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "need help in understanding classpath?" Watch "need help in understanding classpath?" New topic
Author

need help in understanding classpath?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 923
    
    1

please consider the following

javac -d bin -sourcepath src
-classpath C:\classes;E:\lib\junit.jar
src\com\elharo\gui\MainFrame.java

i understand that -sourcepath option is for locating source file and that those source files referenced directly or indireclty by MainFrame.java(the file i'm compiling) will be compiled and put into the argument specified by -d option. what i don't understand is why we are using -classpath option here. what it does ? because we use -classpath option when we are invoking JVM using java from command-line.


OCPJP 6(100 %) OCEWCD 6(91 %) OCPJBCD(93%)
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1469
    
    5

gurpeet singh wrote:what i don't understand is why we are using -classpath option here. what it does ? because we use -classpath option when we are invoking JVM using java from command-line.

Yes, you are right that we use -classpath option while running the class file, but that doesn't mean that the option -classpath cannot be used during compilation.

Consider below scenario:
You are using some junit classes in one of your source files. Then, how java compiler (javac) would know that what this class is, and where the class file for this class is located and what are the methods and arguments and so on? Of course the -classpath option!

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 923
    
    1

yeah thanks alot Anayonkar.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1469
    
    5

You are welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help in understanding classpath?
 
Similar Threads
Why javac does not find this Java file?
Problems compiling packages #2 with JSP
JDOM and JBuilder3
help understanding the package declaration...
How to use relative directory locations when compiling?