While running Java program using command line/server, I always got confused about using -jar option and -cp option. We bundle the application in jar file using maven/gradle or any building tool. Now there may some resource files which should be provided from outside of the application. This is very common and ideal practice.
Now if you use
Java won’t read classpath resources and will look for classpath mentioned in app.jar manifest file.
So, in such case,
Now, Java will search for the jar file and resources in classpath (separated by ; in windows and : in unix).
if you are not providing any -cp option, java checks System’s CLASSPATH and uses the directories.
If there is no envrionment variable CLASSPATH set, then it checks the current directory
Any arguments provided after the main class name will be considered as program arguments
You can pass JVM arguments before the main class and after -cp option with -D as prefix
Have a nice day :)