There are several classes in the JAR file ( Test.jar ) with the main method ( Class1 , Class2 ).

How to run a given class from the console?

 java -jar Test.jar Class1 java -jar Test.jar Class2 
  • one
    How does the jar run? Console application with command line / Java Web Start / applet? - default locale
  • console java -jar Test.jar Class1. java -jar Test.jar Class2 - Daniyar Myrzakanov

1 answer 1

At startup, you can specify any executable class. In order to have a class available from a given JAR, you need to add it to the classpath:

 java -cp Test.jar Class1 

If the parameter Main-Class is registered in the JAR manifest

 Manifest-Version: 1.0 Main-Class: Class1 

, then the specified class will be launched when the executable JAR is started:

 java -jar Test.jar 

References: