Simple java class call example


I’m sorry as I wrote in another post, I come back into openFL for many years and I’m a bit lost about how things have changed so I permit to ask maybe a basic question.

In the past I used to deal with JNI in order to include java classes into an NME project.
I’ve taken look into some posts about JNI and it seems to have changed.

So, my concrete question is :
Let’s say I’ve a Java class that return me a result using a static class, something like that :

public class JavaClass{
    public static String getString () {
        return "Take this one";

This class lays near my .hx files in Source directory.
How do I make a call from .hx file to this java getString function please, soimething like that ?


class Main extends Application {
	public function new () {
		trace( MyRemoteJavaClass.getString() );

As this question is very basic, not related to any external libs in a big project, I think it can help people who looks for something like that in the futur.

First I think I have to tell the .xml project file where to find this class and then make a “link” from this class to the .hx file in order to be able to access it from my .hx file…

Many thnaks for your advices !

var javaCall = lime.system.JNI.createStaticMethod("JavaClass", "getString", "()V");


Thanks Rainy for your answer.

Ok so it’s quite the same as before !

How should I tell the project.xml file where to find the class please (and kind of embed it) ?

And by the way, if I have to include an external java lib, how can I do please ?

<dependency name="libname" path="dependencies/libname" />

Through this, you can import the library into the deps directory.