# JVM target a few questions

**URL:** https://community.haxe.org/t/jvm-target-a-few-questions/2444
**Category:** Haxe
**Tags:** haxe-jvm, haxe-java
**Created:** [May 16, 2020, 2:58pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444 "2020-05-16T14:58:30Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![AlexKotik](https://avatars.discourse-cdn.com/v2/letter/a/2bfe46/32.png) [@AlexKotik](https://community.haxe.org/u/AlexKotik)
#### Post date: [May 16, 2020, 2:58pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/1 "2020-05-16T14:58:30Z")

</div>

I’m on Haxe 4.0.5 yet, still waiting for 4.1.0 to arrive in Manjaro packages. And I’m experimenting with the JVM backend, I’m looking forward to use Haxe to glue together quite a few JVM libraries with my business logic written in Haxe, as I don’t generally like Java or Maven ecosystem or IntelliJ/Eclipse, but want to use those libraries. But anyway.

I was wondering why ‘–java-lib’ is not listed in the ‘–help’ of the compiler? I’ve had some hard time digging it up, so I could include some jars to Haxe project. Also the documentation on Java/JVM target is very lacking. “-D jvm” is kinda hard to find too.

Is it possible to add all jars in some specific folder, so I don’t have to add each jar manually to build.hxml? I’m having quite a few of them. For example I’m planning to use Apache Tika which is 118 jars and it will be a nightmare to add --java-lib for all of those manually.

Also I tried out calling Javalin library (which is a micro web framework) from Haxe, but after just importing it and referencing one class I got an error at compile time: “type not found java.util.function.consumer”. Why is it happening? Can I fix it somehow?

---

<div class="post-metadata">

### Author: ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)
#### Post date: [May 16, 2020, 3:06pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/2 "2020-05-16T15:06:46Z")

</div>

I’m not sure about Haxe 4.0, but on the latest one there is `--java-lib <file> add an external JAR or class directory library` listed in the `--help` output 🙂

And yeah, since JVM target is pretty new there is not a lot of documentation, feel free to contribute 🙂

I don’t think there’s a way to include “all jars in a directory” with just Haxe, you have to write some script to do that. Maybe it would be a good feature though, I’m not sure.

Regarding the last one I think you’re hitting [[display] package completion fails if it contains 'function' · Issue #7697 · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/issues/7697), and probably you can’t do much about it until it’s fixed…

---

<div class="post-metadata">

### Author: ![AlexKotik](https://avatars.discourse-cdn.com/v2/letter/a/2bfe46/32.png) [@AlexKotik](https://community.haxe.org/u/AlexKotik)
#### Post date: [May 16, 2020, 5:34pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/3 "2020-05-16T17:34:33Z")

</div>

> [@nadako](#):
>
> I’m not sure about Haxe 4.0, but on the latest one there is `--java-lib <file> add an external JAR or class directory library` listed in the `--help` output

In Haxe 4.0.5 in “–help” in the “Target-specific” options we only have:

```haxe
  --swf-version <version> change the SWF version
  --swf-header <header> define SWF header (width:height:fps:color)
  --flash-strict more type strict flash API
  --net-std <file> add a root std .NET DLL search path
  --c-arg <arg> pass option <arg> to the native Java/C# compiler

```

Or am I missing something?

> [@nadako](#):
>
> And yeah, since JVM target is pretty new there is not a lot of documentation, feel free to contribute

It is not about the new JVM target, it is about the Java target in general, for example in the manual we only have one article: [Getting started with Haxe/Java - Haxe - The Cross-platform Toolkit](https://haxe.org/manual/target-java-getting-started.html) where there is no info about importing jars. I don’t think I am experienced enough with Haxe to work on docs, sadly.

> [@nadako](#):
>
> I don’t think there’s a way to include “all jars in a directory” with just Haxe, you have to write some script to do that. Maybe it would be a good feature though, I’m not sure.

Well, yes, having this feature would be nice. I think I can make a script to unpack all the jars in a folder and then pack all the class files to a single uber-jar. Also it seems that Haxe compiler is okey parsing a folder of class files, so technically I may just unpack the class files from the jars to a single folder. Don’t know if it will be fine, as jars also may contain metadata and resources, so I might break something this way. And I need a way to package all class files with my Haxe code to a single uber-jar. This stuff will need some testing.

> [@nadako](#):
>
> Regarding the last one I think you’re hitting

So this is because ‘function’ is a keyword in Haxe, right? But I’m not actually using java.util.function.consumer in my code. It seems that it bugs out when the jar I’m referencing uses java.util.function.consumer or something.

---

<div class="post-metadata">

### Author: ![nanjizal](https://community.haxe.org/user_avatar/community.haxe.org/nanjizal/32/239_2.png) [@nanjizal](https://community.haxe.org/u/nanjizal)
#### Post date: [May 18, 2020, 8:55am UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/4 "2020-05-18T08:55:39Z")

</div>

Hi AlexKotik

RE: Java target docs.

These are some info I created on Java target on the old site, it my well be very out of date and I am not sure if I found all links below, when the new site was created I was not involved, and relevant ones have not been updated and transferred.

I think quite a bit of java and flash stuff has more documentation on the old site. I have read a lot on Java but I have only every coded any Java via Haxe which I guess is rather unusual, I think I was probably one of the first to really explore the Haxe Java target, as a way of learning some Java.

At the time I mostly explored Swing/AWT because -lib-java only worked on some Jars and these worked without jars, I believe it now works with JavaFX. Caue and others have improved Java target no end since the early days, pretty much all the ‘sys’ package should work with Haxe Java so any reading and writing files.

> **[Getting started with Haxe/Java - Haxe](http://old.haxe.org/doc/start/java)**

[Haxe/Java Tutorial - Haxe](http://old.haxe.org/doc/java) - some of my tutorials and others  
[Getting Started with OpenGL using lwjgl - Haxe](http://old.haxe.org/doc/java/lwjgl)  
[Graphics 2D, AWT, Swing canvas. - Haxe](http://old.haxe.org/doc/java/graphics2d)

Cambiata forked one Java demo from my old repo, he may have one or two other interesting Java on his repo.

> **[cambiata/hx\_swing\_examples](https://github.com/cambiata/hx_swing_examples)**
>
> Haxe swing examples. Contribute to cambiata/hx\_swing\_examples development by creating an account on GitHub.

There in a swing Java examples I worked on with Azrafe7 with pathfinding engine we ported  
[https://github.com/hxDaedalus/hxDaedalus-swing-exampleshttps://github.com/hxDaedalus/hxDaedalus/tree/master/src/wings/javaSwing](https://github.com/hxDaedalus/hxDaedalus-swing-exampleshttps://github.com/hxDaedalus/hxDaedalus/tree/master/src/wings/javaSwing)

Then my Jigsaw engine has Haxe Java Swing example

> **[nanjizal/JigsawX](https://github.com/nanjizal/JigsawX/tree/master/jigsawxtargets/hxjava)**
>
> master/jigsawxtargets/hxjava

Basis is an interesting Haxe Java project that might be worth a look.

> **[Randonee/BasisAndroid](https://github.com/Randonee/BasisAndroid)**
>
> Native Android application development with haxe. Contribute to Randonee/BasisAndroid development by creating an account on GitHub.

This is another Java haxe related project that’s interesting.

> **[jtransc/jtransc](https://github.com/jtransc/jtransc)**
>
> Bytecode to source converting Java &amp; Kotlin code into JavaScript, C++, D, C#, PHP, AS3, Dart and Haxe and run it everywhere. Also use JVM code in your favourite language as a library. - jtransc...

The other place to look for Haxe Java code is in the toolkits, they all connect with Java to provide android extensions, but often they are too complex to be really much use for understanding more around Haxe Java use.

Anyway hope something in the links I posted is useful, although I expect you found these already. I have not tried JVM target yet.

---

<div class="post-metadata">

### Author: ![Simn](https://community.haxe.org/user_avatar/community.haxe.org/simn/32/388_2.png) [@Simn](https://community.haxe.org/u/Simn)
#### Post date: [May 18, 2020, 11:22am UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/5 "2020-05-18T11:22:08Z")

</div>

I heartily recommend ignoring everything related to the Java target, especially all this outdated information. Our focus for the future will be on the JVM target.

---

<div class="post-metadata">

### Author: ![nanjizal](https://community.haxe.org/user_avatar/community.haxe.org/nanjizal/32/239_2.png) [@nanjizal](https://community.haxe.org/u/nanjizal)
#### Post date: [May 21, 2020, 10:59pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/6 "2020-05-21T22:59:13Z")

</div>

The Haxe manual was written by Simn above, now the main complier writer, it is very technical orientated so it’s ideal for providing a language specification and is an amazing piece of work, but as numerous people have pointed out it’s not always suitable to learn Haxe if you don’t already mostly know Haxe unless perhaps your a compiler writer, So you won’t be the first to complain you could not find details, they are normally in there somewhere, a reasonably simple language but with the various ecosystems becomes complex.

Often the old manual has more verbose entries that are more useful for some aspects, Simn was never a fan of the first manual, it was a mess and not as technically accurate - he never quite understood that not everyone has his mind and I am sure I am not the only one that normally checks both, mainly because others have told my they do as well. For most users the haxe cookbook is often the ideal place to explore and then chat on the haxe discord.

> **[Haxe Beginner articles overview - Beginner - Haxe programming language cookbook](https://code.haxe.org/category/beginner/)**
>
> Overview of Haxe beginner snippets and tutorials.

> **[Discord - A New Way to Chat with Friends & Communities](https://discord.com/invite/Agt3sJA)**
>
> Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

While I am sure JVM is wonderful there is no reason not to explore the Java target, I do not think it will be removed anytime soon it’s now fairly mature, I think he just hates maintaining less interesting languages he’s determined to remove flash! Hopefully the width of users moderates his passion for perfection with the pragmatism that we all end up having to code some PHP or something horrible at one time or another and that’s when it’s great Haxe can help.

---

<div class="post-metadata">

### Author: ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)
#### Post date: [May 21, 2020, 11:05pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/7 "2020-05-21T23:05:44Z")

</div>

In my opinion, the java (and c#) target is not mature and does not work well, and has some critical problems such as type parameters and copy-on-cast.

---

<div class="post-metadata">

### Author: ![nanjizal](https://community.haxe.org/user_avatar/community.haxe.org/nanjizal/32/239_2.png) [@nanjizal](https://community.haxe.org/u/nanjizal)
#### Post date: [May 21, 2020, 11:55pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/8 "2020-05-21T23:55:20Z")

</div>

Well Java Swing has always seemed pretty stable to me with Haxe.

My JigsawX still works on Mojave, I think it was originally created on Leopard or Tiger so with Haxe a long time ago.  
just download the jar and tablecloth.jpg

> **[nanjizal/JigsawX](https://github.com/nanjizal/JigsawX/tree/master/bin)**
>
> master/bin

from terminal just run ( make sure image is next to it ).  
java -jar JigsawxJava.jar

I have not tried building it recently but have updated over the years once or twice, I think it may have an attempt at using threads, I have not done any threads on any other haxe target yet.

Being able to create stuff like that seems pretty stable it works as well as my Kha, Javascript canvas/dom, Flash or OpenFL/NME versions.

Then I am pretty sure the hxDaedalus Swing example works well, created with Azrafe7.

> **[hxDaedalus/hxDaedalus-swing-examples](https://github.com/hxDaedalus/hxDaedalus-swing-examples)**
>
> hxDaedalus haxe java swing examples. Contribute to hxDaedalus/hxDaedalus-swing-examples development by creating an account on GitHub.

I presume these still work with the current compiler ?

I guess since Caue does not get much time to contribute the Java and C# targets get neglected compared to some, but when Franco was too busy that happened with PHP but then it was later rebuilt. Seems a lot of negativity to Java target, for terminal stuff it’s always worked extremely reliably without giving me problems, I guess your talking about integrating with large Java ecosystems, well that’s never completely simple due to amount of tooling and workflows they often have, the only target haxe blends seamlessly with was the flash target, for instance I use haxe js all the time but you can’t just dump some haxe js in angular2 without tweaking it.

Maybe there are some compiler details for the Java target but if you just want to create something in Java swing/awt or slick2d then it’s fine.

---

<div class="post-metadata">

### Author: ![Simn](https://community.haxe.org/user_avatar/community.haxe.org/simn/32/388_2.png) [@Simn](https://community.haxe.org/u/Simn)
#### Post date: [May 22, 2020, 6:28am UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/9 "2020-05-22T06:28:07Z")

</div>

Let us please stay on topic, which is the JVM target. The Java target is a completely different thing and as I said, it is not our future.

---

<div class="post-metadata">

### Author: ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)
#### Post date: [June 11, 2020, 8:09pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/10 "2020-06-11T20:09:27Z")

</div>

> [@AlexKotik](#):
>
> Is it possible to add all jars in some specific folder, so I don’t have to add each jar manually to build.hxml? I’m having quite a few of them. For example I’m planning to use Apache Tika which is 118 jars and it will be a nightmare to add --java-lib for all of those manually.

Grab a Haxe nightly build, this was just merged. 🙂

> <https://github.com/HaxeFoundation/haxe/pull/9551>

---

<div class="post-metadata">

### Author: ![AlexKotik](https://avatars.discourse-cdn.com/v2/letter/a/2bfe46/32.png) [@AlexKotik](https://community.haxe.org/u/AlexKotik)
#### Post date: [June 24, 2020, 9:44am UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/11 "2020-06-24T09:44:09Z")

</div>

That’s awesome, thanks!

---

<div class="post-metadata">

### Author: ![AlexKotik](https://avatars.discourse-cdn.com/v2/letter/a/2bfe46/32.png) [@AlexKotik](https://community.haxe.org/u/AlexKotik)
#### Post date: [September 6, 2020, 6:35pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/12 "2020-09-06T18:35:25Z")

</div>

I tried --java-lib with 4.1.3 and it didn’t work (Sys\_error(“Is a directory”)). It was merged on 11th of June, and Haxe 4.1.3 was released on 22nd of July, is it still not there yet?

---

<div class="post-metadata">

### Author: ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)
#### Post date: [September 6, 2020, 7:16pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/13 "2020-09-06T19:16:38Z")

</div>

4.1.3 is a patch release, which usually don’t have new features, just bug fixes.

---

<div class="post-metadata">

### Author: ![davidbruce](https://community.haxe.org/user_avatar/community.haxe.org/davidbruce/32/555_2.png) [@davidbruce](https://community.haxe.org/u/davidbruce)
#### Post date: [October 20, 2020, 10:29pm UTC](https://community.haxe.org/t/jvm-target-a-few-questions/2444/14 "2020-10-20T22:29:05Z")

</div>

@Gama11 Thanks for fixing this; it makes working with maven dependencies painless. When is Haxe 4.2.0 expected to be released?
