File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in classpath ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in classpath ?" Watch "doubt in classpath ?" New topic

doubt in classpath ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924

Please refer the link the given link says

By default, javac and javadoc search the user class path for both class files and source code files. If the -sourcepath option is specified, javac and javadoc search for source files only on the specified source file path, while still searching the user class path for class files.

to test this, i created source code file as below:

i put the above file in c:\users\g\world directory. then i set the classpath as set classpath=c:\users\g\world. then i ran javac from the d: root drive as d:\> javac according to above link javac by default searches user classpath for source file and class file so it should have compiled . what is the reason ?
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

I don't think it works that way. When you write the command javac, the file should be in the current directory where you run the javac command. If lets say your world.HelloWorld class use a class globe.MyGlobe[tt], then the [tt]globe\ file will be searched in the classpath. Even in that case your classpath should contain the parent directory of globe directory (so in your case your classpath should contain C:\users\g not C:\users\g\world)...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: doubt in classpath ?
It's not a secret anymore!