COMMUNITY

JVM target problem (Type not found : java.util.function.Consumer)

Hi,

I’m trying to create a simple webservice with jvm target. I’ve added jars for Spark with --java-lib switch, but I’m getting this error if I try to import anything from spark namespace:
spark-core-2.9.2.jar@spark/Service.class@initExceptionHandler:1: character 1 : Type not found : java.util.function.Consumer

I’ve found this thread: JVM target a few questions where @AlexKotik was having the the same problem with Javalin; @nadako mentioned https://github.com/HaxeFoundation/haxe/issues/7697, but that seems to be fixed and the same thing happens with the latest nightly build of haxe.

I’ve tried OpenJDK 8, 11 and GraalVM, same thing.

Sounds like some versioning problem. Try haxelib update hxjava, although I doubt that you have such an old version of it installed…

1 Like

Yes, that fixes the compilation problem. Thank you.

Now, I have to figure out how to actually use this thing from Haxe. Simple, java-style handler:

spark.Spark.get(’/’, (req, res) -> ‘Hello’);

fails with:

src/Main.hx:9: characters 5-48 : Could not find a suitable overload, reasons follow
src/Main.hx:9: characters 5-48 : Overload resolution failed for (path : String, route : spark.Route) -> Void
src/Main.hx:9: characters 26-47 : (req : Unknown<0>, res : Unknown<1>) -> String should be spark.Route
src/Main.hx:9: characters 26-47 : … For function argument ‘route’
src/Main.hx:9: characters 5-48 : Overload resolution failed for (path : String, acceptType : String, route : spark.Route, transformer : spark.ResponseTransformer) -> Void
src/Main.hx:9: characters 26-47 : (req : Unknown<0>, res : Unknown<1>) -> String should be String
src/Main.hx:9: characters 26-47 : … For function argument ‘acceptType’
src/Main.hx:9: characters 5-48 : Overload resolution failed for (path : String, route : spark.TemplateViewRoute, engine : spark.TemplateEngine) -> Void
src/Main.hx:9: characters 26-47 : (req : Unknown<0>, res : Unknown<1>) -> String should be spark.TemplateViewRoute
src/Main.hx:9: characters 26-47 : … For function argument ‘route’
src/Main.hx:9: characters 5-48 : End of overload failure reasons

If I don’t find other solution, I guess I could write some kind of wrapper in java.

Does anyone know of some lightweight JVM web server/framework, which could be easily used from Haxe?

You’re probably running into https://github.com/HaxeFoundation/haxe/issues/9576 which isn’t solved yet.

Though I don’t know which of these signatures would match your call even if it did work. Could you point me to the API documentation of that method and tell me which overload it’s supposed to pick up?

Edit: Ah, I missed that spark.Route is also an interface. In that case the signature is obvious.

What would be the simplest way to create “Hello world” microservice on JVM with haxe?
I’ve used Spark because it looked simple enough, but there are probably better ways.

Have you considered using a native Haxe library (which would then even work on multiple Haxe targets)? Something like https://github.com/haxetink/tink_web perhaps.

Yes, a native Haxe lib would be much better solution (being cross-platform), but I haven’t found any.
Does think_web really support JVM? There are only js & php examples on the website.