简体   繁体   English

关于Java中的import语句

[英]About import statement in Java

test.java : test.java

import javax.media;

Which directories are javax.media searched from? 从哪个目录搜索javax.media

I suppose those in CLASSPATH specified by javac -cp will of course be searched. 我想当然会搜索javac -cp指定的CLASSPATH那些。

But will it also search in the directory where test.java locates? 但是它还会在test.java所在的目录中搜索吗?

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 . 对于sun的javac,搜索顺序在其手册中进行了描述。

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. 根据手册的详细信息,在CLASSPATH环境变量中设置的路径中的类文件,在-classpath命令行选项中设置的路径中的类文件,在'-sourcepath option, source files in user classpath (if中的路径中的option, source files in user classpath (if isn't given), and either the JVM's default boot and extension paths or the paths given by the -sourcepath isn't given), and either the JVM's default boot and extension paths or the paths given by the -bootclasspath and -extdirs`选项isn't given), and either the JVM's default boot and extension paths or the paths given by the

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. 由于javax.media是JVM扩展,因此javac可以在JVM的扩展目录中找到,也可以在-extdirs提供的目录中找到,然后在用户类文件夹中,然后在用户源文件夹中。

The simplified version is: It's only directories and jars in your classpath, but quite often people put "." 简化的版本是:它仅是您的类路径中的目录和jar,但很多时候人们都将“”。 in their classpath which would allow searching of directories under the current in the same way as any other classpath directory. 在其类路径中,这将允许以与其他任何类路径目录相同的方式搜索当前目录下的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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