File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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: 924
    
    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.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    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: 924
    
    1

yeah thanks alot Anayonkar.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    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?
How to use relative directory locations when compiling?
Problems compiling packages #2 with JSP
help understanding the package declaration...
JDOM and JBuilder3