Another way to set the classpath is by defining it globally using an environment variable.
For Windows:
set CLASSPATH=C:\myproject\lib\some-library.jar;C:\myproject\classes;
For macOS/Linux:
export CLASSPATH="/home/user/myproject/lib/some-library.jar:/home/user/myproject/classes"
This method is useful when you don’t want to specify the classpath every time you run Java.
Downside?
Setting the Java classpath this way applies globally, so it might affect other Java projects if you’re not careful!