The example you finally gave, -cp is a parameter to the command, which is java. Parameters are generally program-specific, in this case cp stands for Class Path, which is another location java will search to find the class files as they are needed by the program.

Answer from iain on Stack Exchange
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 736630 โ€บ java โ€บ cp-javac-command
How to use -cp in javac command? (Beginning Java forum at Coderanch)
For example if the javac command is issued in the packageb folder the the class path would need to point to the folder up one level: javac -cp ..\.;. ClassB.java (that uses Windows path notations, I don't know the unix version); ... The Unix/Linux syntax would be "javac -cp ..:. ClassB.java".
Discussions

Differences between "java -cp" and "java -jar"? - Stack Overflow
This way you can build the app with other version and add the actual 3rd party dependency to class-path on the command line when running it on different systems. ... There won't be any difference in terms of performance. Using java - cp we can specify the required classes and jar's in the classpath ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Linux Java cp command - Stack Overflow
Explore Stack Internal ... Save this question. Show activity on this post. I'm on linux centos6 I run this command successfully : java -cp "com.opendoorlogistics.connect.jar:com.opendoorlogistics.studio.jar" com.opendoorlogistics.connect.CommandLine -rb batchfile.odlbat More on stackoverflow.com
๐ŸŒ stackoverflow.com
[JAVA] What does the command -cp stand for in the command line?
It tells the Java interpreter where to look for class files. "cp" is for "class path". This is in the manual. More on reddit.com
๐ŸŒ r/learnprogramming
2
3
January 8, 2015
command line - Including all the jars in a directory within the Java classpath - Stack Overflow
Remind: - Windows path separator is ; - Linux path separator is : - In Windows if cp argument does not contains white space, the "quotes" is optional ... windows example doesn't work for java 8 and earlier: see bugs.openjdk.java.net/browse/JDK-8131329 2018-07-18T16:34:37.393Z+00:00 More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 592115 โ€บ java โ€บ Explanation-java-cp-command
Explanation of java -cp command (Java in General forum at Coderanch)
September 10, 2012 - So you're telling the JVM that you want $JBOSS_HOME/bin/client/jboss-client.jar to be on the classpath, and that you want . (the current working directory) to be on the classpath. test.Client is the name of the class the JVM should execute. Everything after that will be command line arguments that are fed to test.Client's main method. ... You should find the -cp tag here.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 546994 โ€บ engineering โ€บ java-cp-windows-linux-differences
java -cp windows and linux differences (General Computing forum at Coderanch)
All, may be useful: classpath definitions in command line differs if you use windows o.s. or linux: windows: java -cp "/myJarDirectoryFullPath/theJarfileToInclude.jar;." myCompiledJavaProgram linux: java -cp "/myJarDirectoryFullPath/theJarfileToInclude.jar:." myCompiledJavaProgram note the ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 30955336 โ€บ linux-java-cp-command
Linux Java cp command - Stack Overflow
Explore Stack Internal ... Save this question. Show activity on this post. I'm on linux centos6 I run this command successfully : java -cp "com.opendoorlogistics.connect.jar:com.opendoorlogistics.studio.jar" com.opendoorlogistics.connect.CommandLine -rb batchfile.odlbat
๐ŸŒ
Tech Monitor
techmonitor.ai โ€บ what-is โ€บ what-is-java-cp
What is Java -cp? - Tech Monitor
June 27, 2023 - Java -cp is a parameter in the Java Virtual Machine or Java compiler that specifies the location of classes and packages defined by the user.
Find elsewhere
๐ŸŒ
Tech Monitor
techmonitor.ai โ€บ what is
What is Java -cp? - Tech Monitor
March 2, 2023 - The CLASSPATH parameter can either be set via the command line or through an environment variable. The -cp parameter specifies a list of directories, JAR archives and ZIP archives to search for class files.
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ java examples โ€บ java โ€“ set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ java classpath syntax in linux vs. windows
Java Classpath Syntax in Linux vs. Windows | Baeldung
January 8, 2024 - However, if we take a closer look at the Java man page on Linux, it says the classpath separator is the semicolon (;). For example, the man page of the java command from the latest(ver.17) OpenJDK shows: โ€“class-path classpath, -classpath classpath, or -cp classpath A semicolon (;) separated list of directories, JAR archives, and ZIP archives to search for class files.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ [java] what does the command -cp stand for in the command line?
r/learnprogramming on Reddit: [JAVA] What does the command -cp stand for in the command line?
January 8, 2015 -

I've started a java course in university and they teach when you run a java file you type "java -cp . HelloWorldApp".

I have always typed "java HelloWorldApp" and the program has always run fine for me. What's the difference?

Thanks!

๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ understanding-the-java-cp-command-parameter โ€บ cdb3eaa20e49e76bdbfd5c0cb5e855c2
Understanding the Java -Cp Command Parameter - Oreate AI Blog
December 22, 2025 - Using the -cp parameter helps ensure that required class files are loaded correctly when running a Java program. Next, letโ€™s look at how this works: When executing a Java program from the command line, JVM loads class files based on their ...
๐ŸŒ
JanBask Training
janbasktraining.com โ€บ community โ€บ java โ€บ what-does-the-java-cp-option-do
What does the java cp option do? | JanBask Training Community
October 13, 2022 - java -cp FILE.jar FILE.Main inputfile What does the -cp option mean? For that matter, what does a negative sign in front mean? I've searched everywhere and couldn't find
๐ŸŒ
MIT
web.mit.edu โ€บ 6.031 โ€บ www โ€บ fa17 โ€บ projects โ€บ fb1 โ€บ commandline.html
Running Java Programs with Command-Line Arguments
Open a command prompt and cd into your project folder. Then run the java command with these arguments: java -cp bin:lib/parserlib.jar:lib/physics.jar some.package.Main filename1 filename2 โ€ฆ
Top answer
1 of 16
1340

Using Java 6 or later, the classpath option supports wildcards. Note the following:

  • Use straight quotes (")
  • Use *, not *.jar

Windows

java -cp "Test.jar;lib/*" my.package.MainClass

Unix

java -cp "Test.jar:lib/*" my.package.MainClass

This is similar to Windows, but uses : instead of ;. If you cannot use wildcards, bash allows the following syntax (where lib is the directory containing all the Java archive files):

java -cp "$(printf %s: lib/*.jar)"

(Note that using a classpath is incompatible with the -jar option. See also: Execute jar file with multiple classpath libraries from command prompt)

Understanding Wildcards

From the Classpath document:

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 example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

A class path entry that contains * will not match class files. To match both classes and JAR files in a single directory foo, use either foo;foo/* or foo/*;foo. The order chosen determines whether the classes and resources in foo are loaded before JAR files in foo, or vice versa.

Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo, not in foo/bar, foo/baz, etc.

The order in which the JAR files in a directory are enumerated in the expanded class path is not specified and may vary from platform to platform and even from moment to moment on the same machine. A well-constructed application should not depend upon any particular order. If a specific order is required then the JAR files can be enumerated explicitly in the class path.

Expansion of wildcards is done early, prior to the invocation of a program's main method, rather than late, during the class-loading process itself. Each element of the input class path containing a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory foo contains a.jar, b.jar, and c.jar, then the class path foo/* is expanded into foo/a.jar;foo/b.jar;foo/c.jar, and that string would be the value of the system property java.class.path.

The CLASSPATH environment variable is not treated any differently from the -classpath (or -cp) command-line option. That is, wildcards are honored in all these cases. However, class path wildcards are not honored in the Class-Path jar-manifest header.

Note: due to a known bug in java 8, the windows examples must use a backslash preceding entries with a trailing asterisk: https://bugs.openjdk.java.net/browse/JDK-8131329

2 of 16
287

Under Windows this works:

java -cp "Test.jar;lib/*" my.package.MainClass

and this does not work:

java -cp "Test.jar;lib/*.jar" my.package.MainClass

Notice the *.jar, so the * wildcard should be used alone.


On Linux, the following works:

java -cp "Test.jar:lib/*" my.package.MainClass

The separators are colons instead of semicolons.

๐ŸŒ
Java Code Geeks
examples.javacodegeeks.com โ€บ home โ€บ linux
Linux cp command - Java Code Geeks
July 18, 2022 - The meaning of this cp acronym stands for copy. With this command, you will be able to copy files or directories from one location to another. There are multiple options for the copy command. cp [OPTION] SOURCE DESTINATION โ€“ the simple command ...
๐ŸŒ
CodeJava
codejava.net โ€บ java-core โ€บ tools โ€บ examples-of-using-java-command
java command examples
August 4, 2019 - If you have a source file called ... program that depends on mail.jar library. Assuming the jar file is at the same directory as the class file, type: java -cp mail.jar;. PlainTextEmailSenderNOTES: There must be a dot (.) after the semicolon.If the jar file is inside a directory ...