Java Single Jar file with multiple main method classes

/**
* Sample launcher
*/
public class Launcher {

    public static void main(String[] args) throws Exception {
        if (args != null && args.length > 0) {
            String option = args[0];
            String[] args2 = new String[0];

            if (args.length > 1) {
                args2 = new String[args.length – 1];
                System.arraycopy(args, 1, args2, 0, args2.length);
            }

            if (option.equals(“JbossJavaTCPSender”))
                new JbossJavaTCPSender().exec(args2);
            else if (option.equals(“JbossJavaTCPReceiver”))
                new JbossJavaTCPReceiver().exec(args2);
            else
                System.out.println(“Connot find such class to execute having name [“
                        + option+”]”);
        } else
            {
            System.out.println(“Usage : Provide ClassName as an argument to execute.”);
            System.out.println(“\t[java -jar JbossJavaTCPExample.jar JbossJavaTCPSender]”);
            System.out.println(“\t[java -jar JbossJavaTCPExample.jar JbossJavaTCPReceiver]”);
            }
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s