ClassPath

zhaozj2021-02-08  415

Setting class path structure Settings class paths by using the -classpath option (preferred method) or setting ClassPath environment variables with the JDK tool. C:> JDKTOOL -CLASSPATH PATH1; PATH2 ... C:> SET ClassPath = Path1; Path2 ... Each path ends with a file name or directory, which depends on what is set to set the class path: for the included The .zip or .jar file of the .class file, the path ends with the .zip or .jar file name. For the .class file in the unnamed package, the path is ending with the directory containing the .class file. For the .class file in the named package, the path ends with the directory containing the "root" package (the first package in the full package name). Use a semicolon to separate multiple items. When using the set command, you need to omit the space (=) on both sides of the equal number. Among them, JDKTool can be Java, Javac, Javadoc, and more. See JDK Development Tools for detailed lists. Description The class path tells the Java application where to find a third party and custom class - ie not a Java extension or a class part of the Java platform. In JDK 1.2, JVM and other JDK tools look for classes by searching for platform libraries, library expansion and classpaths in turn (see how to find classes). Most applications class libraries will take advantage of the expansion mechanism. Therefore, you need to set the class path only if you want to load a class library (a) is not in the current directory or its branch package and (b) is not specified by the expanded mechanism. If the user is upgraded from the old version of the JDK, the start settings may include the ClassPath settings that are no longer needed. At this time, any non-application-specific settings should be deleted. Some third-party applications using Java virtual machines may modify the classpath environment variable to include the class libraries they use. This setting can be retained. Class paths (for example: java -classpath ...) can be changed using the -classpath option using Java tools when calling the JVM or other JDK tool. This is the preferred method of changing class paths. You can also change the class path by using the ClassPath environment variable. Note: JDK 1.2 The default path is the current directory. Setting the ClassPath variable or using the -classpath command line switch overrides the default value, so if you want to include the current directory in the search path, you must include ".". Classs can be stored in a directory (folder) or archive (such as classes.zip or classes.jar). See the last understanding path and package name of this document on the working principle of the detailed information and classpaths of the archive file. Important: The old version of the JDK also includes the / Classes item in the default class. This directory is for JDK only and is not used by application classes. The application class should be placed outside the JDK outside. This way, do not need to reinstall the application library when installing new JDK. To use the / Classes directory as an old version, you can run in the current version, but you can't guarantee that they can run in later versions. Use the -classpath options for Java Tools Java Tools Java, JDB, Javac, and Javah have -classpath options, which will replace the default class path or classpaths specified by the ClassPath environment variable. This is a recommended method for changing the class path, as each application can have the class path required and will not interfere with other applications. Runtime Tools Java and JDB also have -CP options.

This option is the abbreviation of -classpath. For very special situations, Java and Javac have a switch that allows you to use the path to find their own class libraries. However, most users have never used these switches. Using the ClassPath environment variable As described in the previous section, the general user will want to use the -classpath command line option. This section describes how to set the ClassPath environment variable or clear the settings left under the previously installed. Set ClassPath At the DOS prompt, use the set command to modify the ClassPath environment variable. The format is: set classpath = path1; path2 ... The path should begin with the letter of the specified drive, such as C: / .... In this way, classes can still be found when changing to different drives (for example, if the path item is started in / ..., and the desired class will be on D: instead of C: Drive ). Clear ClassPath If the ClassPath environment variable is set to an incorrect value, or the startup file or scripter sets an incorrect path, you can clear the ClassPath: C: C: C: C: C: C: C: C:> SET ClassPath = This command only clears the ClassPath of the current session. To make sure you have the correct ClassPath settings in later sessions, you should delete or modify the startup settings. Change Startup Settings If you set the ClassPath variable when the system is started, the location of the lookup looks up depending on the operating system used: operating system method Windows 98 and Windows 95 check the set command in the autoexec.bat file. Windows NT launches the Control Panel, select "System", click the Environment tab, and check the ClassPath variable in the User Variables section. Understanding class paths and package Name Java classes are organized into packages, and these packages are mapped to the directory in the file system. However, it is different from the file system that the full package name should be specified whenever you specify the package name - never specify only part of it. For example, Java.awt.Button's name should always be specified as java.aw. For example, assume that you want a Java runtime environment to find classes called Cool.class in the package uTility.myApp. If the path of the directory is C: / java / myclasses / utility / myApp, the class path should be set to include C: / Java / MyClasses. To run the app, you can use the JVM commands: C:> java -classpath c: / java / myclasses utility.myapp.cool When the application is running, JVM uses class path settings to find in the utility.myApp package Any other class. Note: The full package name should be specified in the command. For example, setting class paths containing C: / Java / MyClasses / Utility and uses command java myapp.cool because it can't find this class. (You may want to know what to define the package name. The answer is: package name is part of the class, and cannot be modified unless it is recompiled the class.) Note: The package specification mechanism is a fun result is that there is more than the same package. The file can actually exist in different directories. For each class, the package name is the same, but the path to each file can start from different directories in the classpath.

转载请注明原文地址:https://www.9cbs.com/read-913.html

New Post(0)