28

I have a jar which contain two main class Class A and Class B. In the manifest i have mentioned Class A . Now i have to execute classB from the same jar . what should be the command.

I dont prefer to make two separate jars.

Thanks

harshit
  • 7,785
  • 22
  • 69
  • 97

3 Answers3

53

This will do the job: java -classpath yourjar.jar youpackage.B

Favonius
  • 13,720
  • 3
  • 53
  • 94
4

Why don't you create a Main class that accepts an argument? That argument will decide whether to execute Class A or Class B then.

limc
  • 38,266
  • 19
  • 97
  • 142
  • This is already supported directly by the java command, no reason to write custom code to do the same thing. – Tony Apr 10 '17 at 17:22
0

Use a command-line switch to identify whether Class A or Class B should be executed.

mellamokb
  • 55,194
  • 12
  • 105
  • 134