I want to use the java.net.http package in my compose desktop application. When I run the application in IntelliJ, everything works fine. But when I build a .deb file using packageDeb and install it via apt, the application crashes due to a java.lang.ClassNotFoundException: java.net.http.HttpClient
when I click on the "Start" button.
Here's the example code:
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import java.net.http.HttpClient
@Composable
@Preview
fun App() {
MaterialTheme {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Button(onClick = {
println("getting httpClient")
val httpClient: HttpClient = HttpClient.newHttpClient()
}) {
Text(text = "Start")
}
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
And the build.gradle.kts:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.0.1"
}
group = "some.group"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "16"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "untitled"
packageVersion = "1.0.0"
}
}
}
Any ideas on how to fix this? java.net.http should be available in Java 16..
Thanks in advance.