0

Here is ex how to call new instance of java obj, but how to import mylib.jar is not explained

For ex. I have mylib.jar and there is class com.example.MyClass.

    public class MyClass{
    public String getHelloPersonName(String name){
          return "Hello, " + name;
    }

I want to create the java class instance and call this method

How to import the .jar file to the lua code, and create an instance of MyClass and call method from it?

function init()

end
7
  • I'm not sure about importing the file into Lua, but maybe you can do something with os.execute, and call java -jar mylib.jar with arguments? Commented Oct 22, 2018 at 8:37
  • @Mark Here is ex how to call new instance of java obj stackoverflow.com/a/35392230/2425851, but how to import mylib.jar is not explained Commented Oct 22, 2018 at 9:04
  • Create program.lua assuming your lib is already loaded in Java. Then run java -cp "lib/luaj-jse-3.0.1.jar;/path/to/mylib.jar" lua program.lua Commented Oct 22, 2018 at 9:26
  • @EgorSkriptunoff nothing happens after run of the command Commented Oct 22, 2018 at 9:48
  • 1
    The link you posted shows an example how to create instance of Java class by using luajava.newInstance(). Try it inside your program.lua. Read LuaJ API about other operations (passing and returning values and so on). Commented Oct 22, 2018 at 13:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.