Skip to content
Advertisement

How to run a class from Jar which is not the Main-Class in its Manifest file

I have a JAR with 4 classes, each one has Main method. I want to be able to run each one of those as per the need. I am trying to run it from command-line on Linux box.

JavaScript

It has directory structure for the main classes as follows:

JavaScript

I know that I can specify one class as main in my Manifest file. But is there any way by which I can specify some argument on command line to run whichever class I wish to run?

I tried this:

JavaScript

And I got this error:

JavaScript

(In the above command, ‘/home/myhome/datasource.properties’ and ‘/home/myhome/input.txt’ are the command line arguments).

Advertisement

Answer

You can create your jar without Main-Class in its Manifest file. Then :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement