https://kotlinlang.org logo
#http4k
Title
# http4k
j

Johannes Wirde

03/29/2024, 9:39 PM
Hello, guys! I just created my first http4k app through your magical wizard and it yields me this error:
Error: Main method not found in class com.example.HelloWorldKt, please define the main method as:
public static void main(String[] args)
... and that is yucky Java stuff... What should I put in my
fun main()
function?
d

dave

03/29/2024, 9:42 PM
I suspect this may be something regarding your envirionment. Just to make sure - I've just generated a completely vanilla toolbox and run the main class from the IDE.. It worked:
How did you run your app?
j

Johannes Wirde

03/29/2024, 9:45 PM
Using the gradle target "run", I can't
No main function
Screenshot 2024-03-29 at 22.32.06.png
d

dave

03/29/2024, 9:51 PM
yeah - ok - this is a problem because you're using a serverless function instead of a server app. But it's easy to get it running. You should already have TestApp.kt - add a couple of lines and then run it from there..
Copy code
package com.example

import org.http4k.server.SunHttp
import org.http4k.server.asServer

val app = HelloWorldAppLoader(emptyMap())

fun main() {
    app.asServer(SunHttp(8000)).start()
}
Then you can browse to:
Copy code
<http://localhost:8000/ping>
j

Johannes Wirde

03/29/2024, 9:58 PM
Ok, it works now! Thanks!
👍 1
3 Views