When running a Java program from the command line, how do you include third-party jar packages? There are actually many methods, most of which involve tinkering with the classloader.

Here I’ll introduce a relatively simple approach: adding all the required jar packages to the classpath before running.

Specifically, you write a shell script that defines a parameter — you can call it CLASSPATH or something else.

CLASSPATH=yourownjar.jar:xxx.jar:/xx/xx/xxx1.jar:”$CLASSPATH”

Note that the jar containing your own main class must also be included in the classpath you define.

Then use the java -classpath command to run:

java -classpath ${CLASSPATH} xx.Main
Source: https://lichuanyang.top/en/posts/65262/