As already mentioned, -cp is intended only to tell jvm on the command line which class to use for the main stream and where it can find libraries (define classpath). In -jar, it expects the path class and main class to be defined in the manifest of the jar file. So the other is for defining things on the command line, while others discover them inside the jar manifest. There is no difference in performance. You cannot use them at the same time, -jar will override -cp.
Although even if you use -cp, it will still check the manifest file. This way you can define some of the class classes in the manifest, and some on the command line. This is especially useful if you have a dependency on any third-party jar that you cannot provide to your assembly or do not want to provide (expecting that it will be found already in the system where it will be installed, for example). Therefore, you can use it to provide external cans. It may vary between systems or may even have a different version on another system (but with the same interfaces). Thus, you can create an application with a different version and add the actual third-party dependency to the class path on the command line when it starts on different systems.
Pehmolelu Feb 03 '17 at 7:21 2017-02-03 07:21
source share