Using Haxe libraries in Java

50 views
Skip to first unread message

Andy Green

unread,
Nov 11, 2012, 5:32:48 PM11/11/12
to haxe...@googlegroups.com
Is it possible to write a library in Haxe, and then use that library from within Java? Is there any way to make the function in this Haxe class accessible from native Java code?

class main{
    public static function returnString(){
        return "I hope it's possible to call this function from Java!";
    }
}

Andy Green

unread,
Nov 11, 2012, 5:35:27 PM11/11/12
to haxe...@googlegroups.com
Also, what should I import in order to make the Haxe class accessible to another Java class (as soon as the above Haxe class has been compiled to Java?)

Marc Weber

unread,
Nov 11, 2012, 5:37:41 PM11/11/12
to haxelang
Excerpts from Andy Green's message of Sun Nov 11 23:32:48 +0100 2012:
> Is it possible to write a library in Haxe, and then use that library from
> within Java? Is there any way to make the function in this Haxe class
> accessible from native Java code?

Haxe generates .java files, doesn't it? Of course you can just use them
within Java porjects. It may be little bit cumbersome to adopt the the
Haxe style of enums etc..

I haven't used the Java backend yet, but I expect it to be similar to
the PHP one.

Marc Weber

Andy Green

unread,
Nov 11, 2012, 5:59:35 PM11/11/12
to haxe...@googlegroups.com
Haxe actually generates multiple Java files. Which package should I import in order to make the generated Java code accessible from an external Java program?





--
-Anderson Green
Cell phone: 703-242-9096
Home phone: 571-283-7415

Marc Weber

unread,
Nov 11, 2012, 6:10:25 PM11/11/12
to haxelang
Excerpts from Andy Green's message of Sun Nov 11 23:35:27 +0100 2012:
> Also, what should I import in order to make the Haxe class accessible to
> another Java class (as soon as the above Haxe class has been compiled to
> Java?)
Get Eclipes, add the .class files to your class path, use ctrl-sthift-O
(auto import of classes)

You puzzle me, if you want to code Java, you should know how imorts in
Java work. Why not just have a look at the Main.java file?

In my sample

# D.hx
class D {
}

#Main.hx
import D;
class Main {
static public ...
}

this turns into this java file:

package haxe.root;
import haxe.root.*;
@SuppressWarnings(value={"rawtypes", "unchecked"})
public class Main extends haxe.lang.HxObject
{
public static void main(String[] args)

So looking at code should be all you have to do ?

Marc Weber

Andy Green

unread,
Nov 11, 2012, 8:52:39 PM11/11/12
to haxe...@googlegroups.com
I figured it out: all I need to do is use an external jar from Eclipse, and then I can access the generated Java classes.
Reply all
Reply to author
Forward
0 new messages