COMMUNITY

JVM target a few questions

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?

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 :slight_smile:

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

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 https://github.com/HaxeFoundation/haxe/issues/7697, and probably you can’t do much about it until it’s fixed…

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

  --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?

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: 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.

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.

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.

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.

http://old.haxe.org/doc/start/java
http://old.haxe.org/doc/java - some of my tutorials and others
http://old.haxe.org/doc/java/lwjgl
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.

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

Then my Jigsaw engine has Haxe Java Swing example

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

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

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.

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.

3 Likes

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.


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.

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.

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

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.

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.

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.

1 Like

Grab a Haxe nightly build, this was just merged. :slight_smile:

2 Likes

That’s awesome, thanks!