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

**URL:** https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603
**Category:** Haxe
**Tags:** haxe-jvm
**Created:** [July 28, 2020, 3:13pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603 "2020-07-28T15:13:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![wds](https://avatars.discourse-cdn.com/v2/letter/w/58f4c7/32.png) [@wds](https://community.haxe.org/u/wds)
#### Post date: [July 28, 2020, 3:13pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/1 "2020-07-28T15:13:25Z")

</div>

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](https://community.haxe.org/t/jvm-target-a-few-questions/2444) where @AlexKotik was having the the same problem with Javalin; @nadako mentioned [[display] package completion fails if it contains 'function' · Issue #7697 · HaxeFoundation/haxe · GitHub](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.

---

<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: [July 28, 2020, 3:37pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/2 "2020-07-28T15:37:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![wds](https://avatars.discourse-cdn.com/v2/letter/w/58f4c7/32.png) [@wds](https://community.haxe.org/u/wds)
#### Post date: [July 28, 2020, 4:37pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/3 "2020-07-28T16:37:48Z")

</div>

> [@Simn](#):
>
> Sounds like some versioning problem. Try `haxelib update hxjava` , although I doubt that you have such an old version of it installed…

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?

---

<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: [July 28, 2020, 5:04pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/4 "2020-07-28T17:04:02Z")

</div>

You’re probably running into [[jvm] automatic conversion of Haxe functions to Java functional interfaces · Issue #9576 · HaxeFoundation/haxe · GitHub](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.

---

<div class="post-metadata">

### Author: ![wds](https://avatars.discourse-cdn.com/v2/letter/w/58f4c7/32.png) [@wds](https://community.haxe.org/u/wds)
#### Post date: [July 28, 2020, 5:38pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/5 "2020-07-28T17:38:11Z")

</div>

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.

---

<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: [July 28, 2020, 8:20pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/6 "2020-07-28T20:20:21Z")

</div>

Have you considered using a native Haxe library (which would then even work on multiple Haxe targets)? Something like [GitHub - haxetink/tink\_web: Tinkerbell Web Framework](https://github.com/haxetink/tink_web) perhaps.

---

<div class="post-metadata">

### Author: ![wds](https://avatars.discourse-cdn.com/v2/letter/w/58f4c7/32.png) [@wds](https://community.haxe.org/u/wds)
#### Post date: [July 28, 2020, 8:37pm UTC](https://community.haxe.org/t/jvm-target-problem-type-not-found-java-util-function-consumer/2603/7 "2020-07-28T20:37:34Z")

</div>

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.
