Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45686
  • 博文数量: 22
  • 博客积分: 536
  • 博客等级: 中士
  • 技术积分: 205
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-11 00:59
文章分类

全部博文(22)

文章存档

2013年(1)

2012年(5)

2011年(16)

我的朋友
最近访客

分类: Java

2011-06-14 03:09:17

The class path tells JDK tools and applications where to find third-party and user-defined classes -- that is, classes that are not Java or part of the Java platform. The class path needs to find any classes you've compiled with the javac compiler -- its default is the current directory to conveniently enable those classes to be found.

The JDK, the JVM and other JDK tools find classes by searching the Java platform (bootstrap) classes, any extension classes, and the class path, in that order. (For details on the search strategy, see .) Class libraries for most applications will want to take advantage of the . You only need to set the class path when you want to load a class that's (a) not in the current directory or in any of its subdirectories, and (b) not in a location specified by the extensions mechanism.

If you are upgrading from an older version of the JDK, your startup settings may include CLASSPATH settings that are no longer needed. You should remove any settings that are not application-specific, such as classes.zip. Some third-party applications that use the Java Virtual Machine may modify your CLASSPATH environment variable to include the libaries they use. Such settings can remain.

You can change the class path by using the JDK tools' when you invoke the JVM or other JDK tools or by using the . Using the -classpath option is preferred over setting CLASSPATH environment variable because you can set it individually for each application without affecting other applications and without other applications modifying its value.


=====================================================================

The Java launcher, java, initiates the Java virtual machine. The virtual machine searches for and loads classes in this order:

  • Bootstrap classes - Classes that comprise the Java platform, including the classes in rt.jar and several other important jar files.
  • Extension classes - Classes that use the Java Extension mechanism. These are bundled as .jar files located in the extensions directory.
  • User classes - Classes defined by developers and third parties that do not take advantage of the extension mechanism. You identify the location of these classes using the -classpath option on the command line (the preferred method) or by using the CLASSPATH environment variable.

=============================================================================

javac的几个值得注意的选项
-cp path or -classpath path Specify where to find user class files, and (optionally) annotation processors and source files. This classpath overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory. See for more details.

If the -sourcepath option is not specified, the user class path is also searched for source files.

If the -processorpath option is not specified, the classpath is also searched for annotation processors.

As a special convenience, a class path element containing a basename of * is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR.

For example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to A.jar;b.JAR, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory. The CLASSPATH environment variable, where defined, will be similarly expanded. Note:   Depending of the configuration of your command line environment, you may have to quote the wild card character, for example, javac -cp "*.jar" MyClass.java.

-Djava.ext.dirs=directoriesOverride the location of installed extensions.
-d directory Set the destination directory for class files. The directory must already exist; javac will not create it. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d C:\myclasses and the class is called com.mypackage.MyClass, then the class file is called C:\myclasses\com\mypackage\MyClass.class.

If -d is not specified, javac puts each class files in the same directory as the source file from which it was generated.

Note:   The directory specified by -d is not automatically added to your user class path.


sourcepath Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

Note:   Classes found through the classpath may be subject to automatic recompilation if their sources are also found.


-s dir Specify the directory where to place generated source files. The directory must already exist; javac will not create it. If a class is part of a package, the compiler puts the source file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -s C:\mysrc and the class is called com.mypackage.MyClass, then the source file will be placed in C:\mysrc\com\mypackage\MyClass.java.


阅读(858) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:jar命令的-e和-C选项

给主人留下些什么吧!~~