Define the class path
The class path allow Java to find classes used by your application.
Class files can be placed in directories.
They can also be packaged inside jar files.
The class path is defined by specifying a set of directories and jar files locations.
In Linux, you have to use colons to separate the elements of the class path:
/opt/myapp/myapp.jar:/opt/myapp/lib/:.:/opt/myapp/ext/'*'
The character asterisk means that only jar files will be looked at to find classes.
The character asterisk (*) is escaped to avoid shell expansion.
The period represent the current directory from within the application was executed.
In Windows, you have to use semicolons to separate the elements of the class path:
C:\myapp\myapp.jar;C:\myapp\lib;.;C:\myapp\ext\*
Note that the package of a class is considered when trying to locate a class.
For example a class 'MyClass
' that has the package 'my.package
' might be located
inside in the sub-directory 'my/package/
' within any of the locations defined in the class path.
/opt/myapp/lib/my/package/MyClass.class
To set the class path you can use one of the following options: -cp
, -classpath
, --class-path
You can also set the class path using the environment variable: CLASSPATH