Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Run a specific Main class from a jar

Tags:

java

main

jar

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.

like image 759
Swagatika Avatar asked Mar 14 '13 10:03

Swagatika


2 Answers

java -cp target/your_file.jar your.package.name.YourClass
like image 67
Karol Król Avatar answered Nov 06 '22 10:11

Karol Król


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

like image 34
rajesh Avatar answered Nov 06 '22 11:11

rajesh