12.9.1 Getting started with Haxe/JVM

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

    Multi-line comments for documentation.
class Main {
    static public function main():Void {
        // Single line comment
        trace("Hello World");

To compile Haxe to JVM bytecode, you'll first need to install the hxjava haxelib. This is the Haxe Java support library, including build scripts and support code. Then run the following from the command line:

haxe --jvm bin/Main.jar --main Main

To save yourself some typing, you may create a .hxml file (say, jvm.hxml) in your project's top-level directory, containing:

--jvm bin/Main.jar
--main Main

and run it with the haxe command:

haxe jvm.hxml

to produce the bin/Main.jar file.

To execute the jar file, you'll need to have a JRE (Java Runtime Environment) installed, such as OpenJDK or a commercially-supported JRE. Then run the jar file using the following command:

java -jar bin/Main.jar
More information