Search code examples
javalinuxbashjarsh

Calling static jave method from .sh file


I have a jar files that holds a lot of classes, in each class there are static methods that I have to call from a shell script.

I have a function class for each module, this class aggregates all the methods in the module.

Example:

public class Functions{
    public static String e1(){return e1.e1();}
    public static Integer e2(){return e2.e2();}
}
public class e1{
    public static String e1(){
        //do something
    }
}
public class e2{
    public static Integer e2(){
        //do something
    }
}

I want to call the functions in the Function class from sh file:

result=$jar.Functions.e1()

I read that this is the only solution:

The only java method you can call from a shell script is the main method of a class, by starting that class with a java command line execution.

Is this correct?


Solution

  • I created a module of runners and in this module I created a lot of main classes. Each main class runs a static function as mentioned above. Then I called the desirable main from the bash function with the java command.