Home > Back-end >  How could I use a method from a Python code in a Java?
How could I use a method from a Python code in a Java?

Time:01-05

So I have a Python script that look like this:

def methodOne():
    print("Hello I am the first method")

def methodTwo():
    print("Hello I am the second method")

And I have a simple Java script like this:

public class helloworld {

    public static void main(String[] args) {
        //Here I want to call the Methods that are in the Python script
    }

}

But I can´t figure out how I could call those methods in the Java file. Is there a way to do this?

CodePudding user response:

You can use Java Runtime. exec() to run python script, As an example first create a python script file using shebang and then set it executable

CodePudding user response:

Try this my friend https://pythonhosted.org/javabridge/java2python.html it might help you with the solution. But I never tried my self

  • Related