Java Path and Java ClassPath
Java PATH and Java CLASSPATH are two confusing environment variables for Java beginners. Both are operating system level environment variables.
What are Environment Variables ?
Environment variables are global system variables accessible by all the processes running under the OS (Operating System).
Java PATH is the environment variable where we specify the locations of binaries. When you run a program from the command line, the operating system uses the PATH environment variable to search for the program in your local file system. In Java, for run any program we use 'java.exe' and for compile java code use 'javac.exe'. These all executable(.exe) files are available in bin folder so we set path up to bin folder. The Operating System will look in this PATH for executable.
Java CLASSPATH is the path for Java application where the classes you compiled will be available. It is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable. If CLASSPATH is not set, it is defaulted to the current directory. If you set the CLASSPATH, it is important to include the current working directory (.). Otherwise, the current directory will not be searched.
Using wildcards in java classpath
Wild cards were introduced from Java 6. Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For ex. a classpath entry consisting simply of * expands to a list of all the jar files in the current directory.
where %MAINCLASS% is the class containing your main method.
How to use a wildcard in the classpath to add multiple jars
where %MAINJAR% is the jar file to launch via its internal manifest.
If you need only specific jars, you will need to add them individually. The classpath string does not accept generic wildcards like Jar*, *.jar, hiber* etc.
The following entry does not work:
Correct entry is :