8

I have a jar file having 2 java classes both having Main methods. Is there a way I can specify while running the jar file, which class to call ? I know that manifest file can be modified to specify the Main class but since only one class can be mentioned, that does not help. I checked the below links, but those dint solve the problem:

https://stackoverflow.com/questions/5474666/how-to-run-a-class-from-jar-which-is-not-the-main-class-in-its-manifest-file

manifest-file execute a main class from a jar

It gives NoClassDefFoundError.

Community
  • 1
  • 1
Swagatika
  • 3,376
  • 6
  • 30
  • 39

3 Answers3

12
java -cp target/your_file.jar your.package.name.YourClass
josliber
  • 43,891
  • 12
  • 98
  • 133
Karol Król
  • 3,320
  • 1
  • 34
  • 37
1

Have a class that acts as a controller. In its main(), invoke other classes based on arguments passed. Add this as the Main-class in manifest

rajesh
  • 3,247
  • 5
  • 31
  • 56
0

Write a Main class in which the main method calls the actual method depending on the command line argument passed. Add this Main class in the manifest.

Kishore
  • 819
  • 9
  • 20