Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a static jar class method from command line

I have a jar file : "CallMeMaybe.jar".

There is a static method callMe() in the main class callmemaybe.CallMeMaybe . Like it is possible to call the main() method from command line by running :

java -cp CallMeMaybe.jar callmemaybe.CallMeMaybe

Is there a way to directly call another static method than main() ?

I would like to do that :

java -cp CallMeMaybe.jar callmemaybe.CallMeMaybe.callMe()
like image 572
kaligne Avatar asked Sep 30 '22 04:09

kaligne


1 Answers

You can't call it directly, but just call it from your main method i.e.

public class Foo {
    public static void main(String[] args) {
        doSomething(args);
    }

    private static void doSomething(String[] args) {
        // your code here
    }
}

Although I don't see the point of the extra method.

like image 160
bcsb1001 Avatar answered Oct 04 '22 20:10

bcsb1001