<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Classpath</id>
	<title>Classpath - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Classpath"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Classpath&amp;action=history"/>
	<updated>2026-05-05T01:15:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Classpath&amp;diff=3299494&amp;oldid=prev</id>
		<title>imported&gt;Citation bot: Added date. | Use this bot. Report bugs. | Suggested by Dominic3203 | Category:Articles containing how-to sections | #UCB_Category 233/794</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Classpath&amp;diff=3299494&amp;oldid=prev"/>
		<updated>2025-01-26T16:37:55Z</updated>

		<summary type="html">&lt;p&gt;Added date. | &lt;a href=&quot;/wiki143/index.php?title=En:WP:UCB&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;En:WP:UCB (page does not exist)&quot;&gt;Use this bot&lt;/a&gt;. &lt;a href=&quot;/wiki143/index.php?title=En:WP:DBUG&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;En:WP:DBUG (page does not exist)&quot;&gt;Report bugs&lt;/a&gt;. | Suggested by Dominic3203 | &lt;a href=&quot;/wiki143/index.php?title=Category:Articles_containing_how-to_sections&quot; title=&quot;Category:Articles containing how-to sections&quot;&gt;Category:Articles containing how-to sections&lt;/a&gt; | #UCB_Category 233/794&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{For|the software|GNU Classpath}}&lt;br /&gt;
{{Multiple issues|&lt;br /&gt;
{{Primary sources|date=November 2020}}&lt;br /&gt;
{{Howto|date=November 2020}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Classpath&amp;#039;&amp;#039;&amp;#039; is a parameter in the [[Java virtual machine|Java Virtual Machine]] or the [[Java compiler]] that specifies the location of user-defined [[Class (computer science)|classes]] and [[Java package|packages]]. The parameter may be set either on the [[Command line interface|command-line]], or through an [[environment variable]].&lt;br /&gt;
&lt;br /&gt;
== Overview and architecture ==&lt;br /&gt;
{{See also|Java class loader}}&lt;br /&gt;
Similar to the classic [[Library (computing)#Dynamic loading|dynamic loading]] behavior, when executing [[Java (programming language)|Java]] programs, the [[Java virtual machine|Java Virtual Machine]] finds and loads classes lazily (it loads the [[Java bytecode|bytecode]] of a class only when the class is first used). The classpath tells Java where to look in the filesystem for files defining these classes.&lt;br /&gt;
&lt;br /&gt;
The virtual machine searches for and loads classes in this order:&lt;br /&gt;
# bootstrap classes: the classes that are fundamental to the [[Java Platform]] (comprising the public classes of the [[Java Class Library]], and the private classes that are necessary for this library to be functional).&lt;br /&gt;
# extension classes: [[Java package|packages]] that are in the &amp;#039;&amp;#039;extension&amp;#039;&amp;#039; directory of the [[Java Runtime Environment]] or [[JDK]], &amp;lt;code&amp;gt;jre/lib/ext/&amp;lt;/code&amp;gt;&lt;br /&gt;
# user-defined packages and libraries&lt;br /&gt;
&lt;br /&gt;
By default only the packages of the [[JDK]] [[Java Platform, Standard Edition|standard API]] and extension packages are accessible without needing to set where to find them. The path for all user-defined [[Java package|packages]] and libraries must be set in the command-line (or in the [[manifest file|Manifest]] associated with the [[JAR (file format)|Jar file]] containing the classes).&lt;br /&gt;
&lt;br /&gt;
== Setting the path to execute Java programs ==&lt;br /&gt;
&lt;br /&gt;
=== Supplying as application argument ===&lt;br /&gt;
Suppose we have a package called &amp;#039;&amp;#039;org.mypackage&amp;#039;&amp;#039; containing the classes:&lt;br /&gt;
* &amp;#039;&amp;#039;HelloWorld&amp;#039;&amp;#039; (main class)&lt;br /&gt;
* &amp;#039;&amp;#039;SupportClass&amp;#039;&amp;#039;&lt;br /&gt;
* &amp;#039;&amp;#039;UtilClass&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
and the files defining this package are stored physically under the directory &amp;#039;&amp;#039;D:\myprogram&amp;#039;&amp;#039; (on [[Microsoft Windows|Windows]]) or &amp;#039;&amp;#039;/home/user/myprogram&amp;#039;&amp;#039; (on [[Linux]]).&lt;br /&gt;
&lt;br /&gt;
The file structure looks like this:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size:90%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! [[Microsoft Windows]]&lt;br /&gt;
! [[Linux]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;pre&amp;gt;&lt;br /&gt;
D:\myprogram\&lt;br /&gt;
      |&lt;br /&gt;
      ---&amp;gt; org\  &lt;br /&gt;
            |&lt;br /&gt;
            ---&amp;gt; mypackage\&lt;br /&gt;
                     |&lt;br /&gt;
                     ---&amp;gt; HelloWorld.class       &lt;br /&gt;
                     ---&amp;gt; SupportClass.class   &lt;br /&gt;
                     ---&amp;gt; UtilClass.class     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| &amp;lt;pre&amp;gt;&lt;br /&gt;
/home/user/myprogram/&lt;br /&gt;
            |&lt;br /&gt;
            ---&amp;gt; org/  &lt;br /&gt;
                  |&lt;br /&gt;
                  ---&amp;gt; mypackage/&lt;br /&gt;
                           |&lt;br /&gt;
                           ---&amp;gt; HelloWorld.class       &lt;br /&gt;
                           ---&amp;gt; SupportClass.class   &lt;br /&gt;
                           ---&amp;gt; UtilClass.class     &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When we invoke Java, we specify the name of the application to run: org.mypackage.HelloWorld. However we must also tell Java where to look for the files and directories defining our package. So to launch the program, we use the following command:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size:90%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! [[Microsoft Windows]]&lt;br /&gt;
! [[Linux]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;pre&amp;gt;&lt;br /&gt;
 java -classpath D:\myprogram org.mypackage.HelloWorld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| &amp;lt;pre&amp;gt;&lt;br /&gt;
 java -cp /home/user/myprogram org.mypackage.HelloWorld &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;java&amp;lt;/code&amp;gt; is the [[Java runtime]] launcher, a type of SDK Tool (A command-line tool, such as [[javac]], [[javadoc]], or [[APT (software)|apt]])&lt;br /&gt;
* &amp;#039;&amp;#039;-classpath D:\myprogram&amp;#039;&amp;#039; sets the path to the packages used in the program (on Linux, &amp;#039;&amp;#039;-cp /home/user/myprogram&amp;#039;&amp;#039;) and&lt;br /&gt;
* &amp;#039;&amp;#039;org.mypackage.HelloWorld&amp;#039;&amp;#039; is the name of the main class&lt;br /&gt;
&lt;br /&gt;
=== Setting the path through an environment variable ===&lt;br /&gt;
The [[environment variable]] named &amp;lt;code&amp;gt;CLASSPATH&amp;lt;/code&amp;gt; may be alternatively used to set the classpath. For the above example, we could also use on Windows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;doscon&amp;quot;&amp;gt;&lt;br /&gt;
D:\myprogram&amp;gt;set CLASSPATH=D:\myprogram&lt;br /&gt;
D:\myprogram&amp;gt;java org.mypackage.HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rule is that &amp;lt;code&amp;gt;-classpath&amp;lt;/code&amp;gt; option, when used to start the java application, overrides the &amp;lt;code&amp;gt;CLASSPATH&amp;lt;/code&amp;gt; environment variable. If none are specified, the [[Working directory|current working directory]] is used as classpath. This means that when our working directory is &amp;lt;code&amp;gt;D:\myprogram\&amp;lt;/code&amp;gt; (on Linux, &amp;lt;code&amp;gt;/home/user/myprogram/&amp;lt;/code&amp;gt;), we would not need to specify the classpath explicitly. When overriding however, it is advised to include the current folder &amp;lt;code&amp;gt;&amp;quot;.&amp;quot;&amp;lt;/code&amp;gt; into the classpath in the case when loading classes from current folder is desired.&lt;br /&gt;
&lt;br /&gt;
The same applies not only to java launcher but also to [[javac]], the java compiler.&lt;br /&gt;
&lt;br /&gt;
=== Setting the path of a Jar file ===&lt;br /&gt;
If a program uses a supporting library enclosed in a [[JAR (file format)|Jar file]] called &amp;#039;&amp;#039;supportLib.jar&amp;#039;&amp;#039;, physically located in the directory &amp;#039;&amp;#039;D:\myprogram\lib\&amp;#039;&amp;#039; and  the corresponding physical file structure is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
D:\myprogram\&lt;br /&gt;
      |&lt;br /&gt;
      ---&amp;gt; lib\&lt;br /&gt;
            |&lt;br /&gt;
            ---&amp;gt; supportLib.jar&lt;br /&gt;
      |&lt;br /&gt;
      ---&amp;gt; org\&lt;br /&gt;
            |&lt;br /&gt;
            ---&amp;gt; mypackage\&lt;br /&gt;
                       |&lt;br /&gt;
                       ---&amp;gt; HelloWorld.class&lt;br /&gt;
                       ---&amp;gt; SupportClass.class&lt;br /&gt;
                       ---&amp;gt; UtilClass.class&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the following [[Command-line interface#Command-line option|command-line option]] is needed:&lt;br /&gt;
&lt;br /&gt;
 java -classpath D:\myprogram;D:\myprogram\lib\supportLib.jar org.mypackage.HelloWorld&lt;br /&gt;
&lt;br /&gt;
or alternatively:&lt;br /&gt;
{{sxhl|2=doscon|1=&lt;br /&gt;
D:\myprogram&amp;gt;set CLASSPATH=D:\myprogram;D:\myprogram\lib\supportLib.jar&lt;br /&gt;
D:\myprogram&amp;gt;java org.mypackage.HelloWorld&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Adding all JAR files in a directory ===&lt;br /&gt;
In [[Java 6]] and higher, one can add all jar-files in a specific directory to the classpath using wildcard notation.&lt;br /&gt;
&lt;br /&gt;
Windows example:&lt;br /&gt;
{{sxhl|2=doscon|1=&lt;br /&gt;
D:\myprogram&amp;gt;java -classpath &amp;quot;.;c:\mylib\*&amp;quot; MyApp&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Linux example:&lt;br /&gt;
{{sxhl|2=console|1=&lt;br /&gt;
$ java -classpath &amp;#039;.:/mylib/*&amp;#039; MyApp&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This works for both &amp;lt;code&amp;gt;-classpath&amp;lt;/code&amp;gt; options and environment classpaths.&lt;br /&gt;
&lt;br /&gt;
=== Setting the path in a manifest file ===&lt;br /&gt;
If a program has been enclosed in a [[JAR (file format)|Jar file]] called &amp;#039;&amp;#039;helloWorld.jar&amp;#039;&amp;#039;, located directly in the directory &amp;#039;&amp;#039;D:\myprogram&amp;#039;&amp;#039;, the directory structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
D:\myprogram\&lt;br /&gt;
      |&lt;br /&gt;
      ---&amp;gt; helloWorld.jar &lt;br /&gt;
      |&lt;br /&gt;
      ---&amp;gt; lib\  &lt;br /&gt;
            |&lt;br /&gt;
            ---&amp;gt; supportLib.jar&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The [[manifest file]] defined in &amp;#039;&amp;#039;helloWorld.jar&amp;#039;&amp;#039; has this definition:&lt;br /&gt;
{{sxhl|2=properties|&lt;br /&gt;
Main-Class: org.mypackage.HelloWorld&lt;br /&gt;
Class-Path: lib/supportLib.jar&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The [[manifest file]] should end with either a new line or carriage return.&lt;br /&gt;
&lt;br /&gt;
The program is launched with the following command:&lt;br /&gt;
 java -jar D:\myprogram\helloWorld.jar [app arguments]&lt;br /&gt;
&lt;br /&gt;
This automatically starts &amp;#039;&amp;#039;org.mypackage.HelloWorld&amp;#039;&amp;#039; specified in class &amp;#039;&amp;#039;Main-Class&amp;#039;&amp;#039; with the arguments. The user cannot replace this class name using the invocation {{code|java -jar}}. &amp;#039;&amp;#039;Class-Path&amp;#039;&amp;#039; describes the location of &amp;#039;&amp;#039;supportLib.jar&amp;#039;&amp;#039; relative to the location of the library &amp;#039;&amp;#039;helloWorld.jar&amp;#039;&amp;#039;. Neither absolute file path, which is permitted in {{code|-classpath}} parameter on the command line, nor jar-internal paths are supported. This means that if the main class file is contained in a jar, &amp;#039;&amp;#039;org/mypackage/HelloWorld.class&amp;#039;&amp;#039; must be a valid path on the root within the jar.&lt;br /&gt;
&lt;br /&gt;
Multiple classpath entries are separated with spaces:&lt;br /&gt;
{{sxhl|2=properties|&lt;br /&gt;
Class-Path: lib/supportLib.jar lib/supportLib2.jar&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== OS specific notes ==&lt;br /&gt;
Being closely associated with the file system, the [[Command-line argument|command-line]] Classpath syntax depends on the operating system.&amp;lt;ref&amp;gt;{{Cite web|url=http://www.antwerkz.com/blog/the-classpath|title=The Classpath|date=6 August 2013 |access-date=2016-06-26}}&amp;lt;/ref&amp;gt; For example:&lt;br /&gt;
&lt;br /&gt;
* on  all [[Unix|Unix-like]] operating systems (such as [[Linux]] and [[Mac OS X]]), the directory structure has a Unix syntax, with separate file paths separated by a [[Colon (punctuation)|colon]] (&amp;quot;:&amp;quot;). &lt;br /&gt;
* on [[Microsoft Windows|Windows]], the directory structure has a Windows syntax, and each file path must be separated by a [[semicolon]] (&amp;quot;;&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
This does not apply when the Classpath is defined in [[manifest file]]s, where each file path must be separated by a space (&amp;quot;&amp;amp;nbsp;&amp;quot;), regardless of the operating system.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Java class loader]]&lt;br /&gt;
* [[Java Platform Module System]]&lt;br /&gt;
* {{Annotated link|rpath}}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://docs.oracle.com/javase/6/docs/technotes/tools/findingclasses.html Note explaining how Java classes are found, on Oracle website]&lt;br /&gt;
* [http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html Specification of how to set the Classpath on Oracle site]&lt;br /&gt;
&lt;br /&gt;
[[Category:Java platform|Classpath]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Citation bot</name></author>
	</entry>
</feed>