简体   繁体   中英

About import statement in Java

test.java :

import javax.media;

Which directories are javax.media searched from?

I suppose those in CLASSPATH specified by javac -cp will of course be searched.

But will it also search in the directory where test.java locates?

And are there any other possible places that will be searched?

Consult the specifications for your compiler. For sun's javac, the search order is described in its manual .

Depending on a few things the manual details, class files in the paths set in the CLASSPATH environment variable, class files in the paths set the -classpath command line option, source files in the paths from the '-sourcepath option, source files in user classpath (if -sourcepath isn't given), and either the JVM's default boot and extension paths or the paths given by the -bootclasspath and -extdirs` options.

As javax.media is a JVM extension, javac would look either in the JVM's extensions directory, or that provided by -extdirs, then in user class folders, then in user source folders.

The simplified version is: It's only directories and jars in your classpath, but quite often people put "." in their classpath which would allow searching of directories under the current in the same way as any other classpath directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM