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,925
  • 23
  • 70
  • 97

3 Answers3

53

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

Favonius
  • 13,959
  • 3
  • 55
  • 95
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
  • 39,366
  • 20
  • 100
  • 145
  • 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
  • 56,094
  • 12
  • 110
  • 136