12.7.1 Getting started with Haxe/Java

To get started with Haxe/Java, create a new folder and save this class as Main.hx.

class Main {
  static public function main():Void {
    trace("Hello World");
  }
}

To compile Haxe to Java we need two obvious prerequisites installed:

Run the following from the command line:

haxe -java bin -main Main

Another possibility is to create and run (double-click) a file called compile.hxml. In this example the hxml-file should be in the same directory as the example class.

-java bin
-main Main

The compiler outputs in the given bin-folder, which contains the generated sources / .jar files which prints the traced message when you execute it.

To execute, run the following command:

java -jar bin/Main.jar
More information