Suppose you have developed a Java application called « MyApp » that requires two external libraries, « dependency1.jar » and « dependency2.jar ». To run your application with these dependencies, you can use the following command-line argument when launching your Java application:
java -cp MyApp.jar:/path/to/dependency1.jar:/path/to/dependency2.jar com.example.MyAppMainClass
Here, the « -cp » option is used to specify the classpath, which is a list of directories and JAR files that the Java Virtual Machine (JVM) uses to look for classes and resources. The colon (« : ») character is used as a separator between the directories and JAR files.
In this example, « MyApp.jar » is the main JAR file that contains your application’s compiled Java classes, and « dependency1.jar » and « dependency2.jar » are two external libraries that your application depends on. The « com.example.MyAppMainClass » argument is the fully qualified name of your application’s main class that contains the « main » method.
By specifying these dependencies in the classpath, the JVM can load the required classes and resources at runtime and enable your application to function correctly.