File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help in understanding classpath?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah thanks alot Anayonkar.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic