Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

07-compiler-usage, added --jvm #466

Merged
merged 4 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content/07-compiler-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The second question usually comes down to providing an argument specifying the d
* `--cpp <directory>` Generate [C++](target-cpp) source code in specified directory and compiles it using native C++ compiler.
* `--cs <directory>` Generate [C#](target-cs) source code in specified directory.
* `--java <directory>` Generate [Java](target-java) source code in specified directory and compiles it using the Java Compiler. Add `-D jvm` to generate JVM byte code directly bypassing Java compilation step.
* `--jvm <file_name.jar>` Generate [JVM bytecode](target-jvm) as a jar file.
* `--python <file_name.py>` Generate [Python](target-python) source code in the specified file.
* `--lua <file_name.lua>` Generate [Lua](target-lua) source code in the specified file.
* `--hl <file_name.hl>` Generate [HashLink](target-hl) byte code in specified file.
Expand Down
48 changes: 48 additions & 0 deletions content/12-target-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,54 @@ java -jar bin/Main.jar



<!--label:target-jvm-->
### JVM

<!--subtoc-->

<!--label:target-jvm-getting-started-->
#### Getting started with Haxe/JVM

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

[code asset](assets/HelloWorld.hx)

To compile Haxe to JVM bytecode, you'll first need to install the [hxjava haxelib](http://lib.haxe.org/p/hxjava). This is the Haxe Java support library, including build scripts and support code. Then run the following from the command line:

```sh
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:

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

and run it with the `haxe` command:

```sh
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](https://openjdk.java.net/) or a commercially-supported JRE. Then run the jar file using the following command:

```sh
java -jar bin/Main.jar
```


##### More information

* [Haxe/Java API docs](https://api.haxe.org/java/)
* [Java Platform Documentation](https://docs.oracle.com/javase/)





<!--label:target-cs-->
### C#
Expand Down