Calling Java Methods from Shell Scripts

Code Hungry :

How to execute a Java method from inside shell scripts?

adarshr :

You can only call the main method. Design your main method such that it calls the method you want.

When I say call main method, you don't explicitly invoke it. It's the only entry point to a java program when you invoke it.

If your class looks like:

package com.foo;

public class Test {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You can use the following command line to invoke the main from within the directory where you can find com/foo/Test.class (If you're in the classes directory in the structure shown far below):

java com.foo.Test

If you want to do so from a different (See the directory structure far below) directory, then you'll have to set classpath.

java -cp /path/to/classes com.foo.Test

Assume the below directory structure for clarity.

-path
    -to
        -classes
            -com
                -foo
                    >Test.class

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling terminal from shell scripts to display results of commands

From Dev

calling objects from other methods in java

From Dev

XPages - Calling Java methods

From Dev

Calling the methods in java

From Dev

Calling Java Methods in XSLT

From Java

Calling multiple methods in Java

From Java

Calling the methods in a class in Java

From Dev

Calling methods on objects Java

From Dev

Calling ruby from shell

From Java

Why calling methods from container class instead of instances of it in Java

From Java

Java: Calling in main implemented Interface Methods from a jUnit - Test

From Dev

Proper/easy way of calling methods from a program on remote server in java?

From Dev

Calling Java Methods from JNI results in program crash

From Java

Java Generics - calling specific methods from generic-typed ones

From Dev

Calling python from perl - methods are not calling properly

From Dev

Calling methods from module in class

From Dev

Calling methods and closures from an array

From Dev

Django calling methods from models

From Dev

Calling Swift Methods from AppleScript

From Dev

Calling JavaScript methods from typescript

From Dev

Calling methods from different threads

From Dev

Calling superclass methods from a subclass

From Dev

Trouble calling methods from a class/

From Java

Calling methods on string literals (Java)

From Java

Calling methods of "parent" component in Java

From Java

Calling two Java methods asynchronously

From Dev

Calling Java methods with React locally

From Java

calling java methods in javascript code

From Dev

Calling methods in a Java Fx ActionEvent