Download Doc - eightfoldit.com

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Centripetal force wikipedia , lookup

Path integral formulation wikipedia , lookup

Transcript
Setting ClassPath
What is ClassPath?
The class path tells JDK tools and applications where to find third-party and user-defined classes -- that
is, classes that are not Java extensions 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 How Classes
Are Found.) Class libraries for most applications will want to take advantage of the extensions
mechanism. 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,
(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.
Need To Set ClassPath?
In java programming language for compiling the program we use the compiler that converts the source
code into the byte code after that, that byte code is interpreted by JVM that converts the bytecode into
the machine independent code. In java how the Java compiler and the JVM use the class search path to
locate classes when they are referenced by other Java code. Searching class path is important for all
Java developers. Many development tools have their own ways of manipulating the class path, which
vary from product to product. For doing this we will use only simple command-line tools to carry out the
compile operations. No difference, between the way that the Java compiler searches for classes, and the
way that the JVM does it at run time. The compiler has the ability to compile classes from source code,
where the JVM does not. We will use the compiler, but similar issues apply at run time.
How To Set ClassPath?
After installing jdk ,you also get jvm automatically installed in your system , but as it is virtual so you
cannot see this.
As you have already studied in previous topic “ JVM Architecture“ that JVM acts as a virtual OS for
executing Java Code , So means somewhere our OS (Windows, Linux etc) has given permission to JVM to
act as a OS for code execution . And this permission is manually given by us by setting the classpath of
JDK bin and lib folder (created in your program files/java folder after installation), The bin directory
contains both the compiler and the launcher, in the current PATH environment variable. The PATH
environment variable is a series of directories separated by semicolons (;). Microsoft Windows looks
for programs in the PATH directories in order, from left to right. You should have only one bin
directory for the JDK in the path at a time (those following the first are ignored), so if one is already
present, you can update that particular entry.
The following is an example of a PATH environment variable:
C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem; &soon..
Path set can be done by two ways:
1) Temporary :Through command prompt we can give instruction to set Path = “ your jdk bin folder location“. This will
support your java instructions and command till you restart your command prompt. After you reopen
your cmd the path variable is reset to its previous value and java instructions will not be recognized by
cmd.
e.g. : C:> set PATH=”C:\Program Files\Java\jdk1.7.0_25\bin”; or
C:\>set path=%path;C:\Java\jdk1.7.0_25\bin C:\Java\jdk1.7.0_25\lib;%
When you open a command prompt and type "javac", you're supposed to have the "bin" directory of
your sdk into the PATH, otherwise you'll get an infamous "Command not found" error message
2) Permanent:It is useful to set the PATH environment variable permanently so it will persist after rebooting. To make
a permanent change to the PATH variable, use the System icon in the Control Panel. The precise
procedure varies depending on the version of Windows:
Windows XP



Select Start, select Control Panel. double click System, and select the Advanced tab.
Click Environment Variables. In the section System Variables, find the PATH environment
variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, , append the jdk bin folder
location followed by ; to the existing value of PATH environment variable .Click OK. Close all
remaining windows by clicking OK.
Windows 7 and 8:




From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the PATH environment
variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

In the Edit System Variable (or New System Variable) window, append the jdk bin folder location
followed by ; to the existing value of PATH environment variable. Click OK. Close all remaining
windows by clicking OK.
Note: You may see a PATH environment variable similar to the following when editing it from the
Control Panel:
%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
Variables enclosed in percentage signs (%) are existing environment variables. If one of these variables is
listed in the Environment Variables window from the Control Panel (such as JAVA_HOME), then you can
edit its value. If it does not appear, then it is a special environment variable that the operating system
has defined. For example, SystemRoot is the location of the Microsoft Windows system folder. To obtain
the value of a environment variable, enter the following at a command prompt. (This example obtains
the value of the SystemRoot environment variable):
echo %SystemRoot%
Checking the CLASSPATH variable (All platforms)
The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user
classes. (Classes that are part of the JRE, JDK platform, and extensions should be defined through other
means, such as the bootstrap class path or the extensions directory.)
The preferred way to specify the class path is by using the -cp command line switch. This allows the
CLASSPATH to be set individually for each application without affecting other applications. Setting the
CLASSPATH can be tricky and should be performed with care.
The default value of the class path is ".", meaning that only the current directory is searched. Specifying
either the CLASSPATH variable or the -cp command line switch overrides this value.
To check whether CLASSPATH is set on Microsoft Windows NT/2000/XP, execute the following:
C:> echo %CLASSPATH%
On Solaris or Linux, execute the following:
% echo $CLASSPATH
If CLASSPATH is not set you will get a CLASSPATH: Undefined variable error (Solaris or Linux) or simply
%CLASSPATH% (Microsoft Windows NT/2000/XP).
To modify the CLASSPATH, use the same procedure you used for the PATH variable.