godot-kotlin-jvm icon indicating copy to clipboard operation
godot-kotlin-jvm copied to clipboard

java 11 module support

Open Frontrider opened this issue 3 years ago • 6 comments

Some java 11 modules do not make it to the classpath of the application. This can be a feature as we strip the things we don't need.

Java modules should be taken a look at somewhere down the line.

Godot-JVM: Starting GC thread
WARNING: JNI local refs: 66, exceeds capacity: 65
Godot-JVM: Loading classes ...
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Time
       at com.google.gson.Gson.<init>(Gson.java:265)
       at com.google.gson.Gson.<init>(Gson.java:186)
       at hu.frontrider.skyforge.model.DataLoader.loadData(DataLoader.kt:53)
       at hu.frontrider.skyforge.model.DataLoader.loadModel(DataLoader.kt:17)
       at hu.frontrider.skyforge.Simple._ready(Simple.kt:26)
       at godot.hu.frontrider.skyforge.SimpleRegistrar$register$1$1$2.invoke(SimpleEntry.kt:18)
       at godot.hu.frontrider.skyforge.SimpleRegistrar$register$1$1$2.invoke(SimpleEntry.kt:13)
       at godot.core.KtFunction0.invokeKt$godot_runtime(Functions.kt:103)
       at godot.core.KtFunction.invoke(Functions.kt:74)
Caused by: java.lang.ClassNotFoundException: java.sql.Time
       at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
       at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
       at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
       ... 9 more
ERROR: check_exceptions: Godot-JVM: An exception has occurred!
  At: modules/kotlin_jvm/src/jni/env.cpp:61.
Godot-JVM: Unloading classes ...
Godot-JVM: Closing GC thread

May not be because of modules, but that is my guess.

Frontrider avatar May 13 '21 21:05 Frontrider

Hello ! Can you try to add sql module to the jre in your project using jlink --add-modules java.base,java.logging,java.sql --output jre ?

piiertho avatar May 15 '21 11:05 piiertho

That command made a new jre folder inside the project's folder.

After further fiddling, this is the point when intellij stopped complaining about missing classes again, compilation fails. https://gist.github.com/Frontrider/840406ffa79fbe402f8f0cfc943d189b

With this setup, it finds the modules that we need, and I'm finally getting errors that I may not be able to resolve from my script. I think I need to exclude godot.runtime from the build. https://gist.github.com/Frontrider/60f830de511cd087defe16f8c42d03a8

The module info was a requirement, and for gamedev I'd say it's an absolute must to trim out the fat from our result.

It also looks like that Kotlin may or may not play well with modules yet, if you only have kotlin code and that requires some hacking like setting the kotlin output directory to the same folder as java.

Frontrider avatar May 16 '21 11:05 Frontrider

@Frontrider Could you comment these two lines: https://github.com/utopia-rise/godot-kotlin-jvm/blob/39828684e65b7d5c717a716c3d02911f74d4d4ad/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/setupConfigurationsAndCompilations.kt#L57 and https://github.com/utopia-rise/godot-kotlin-jvm/blob/39828684e65b7d5c717a716c3d02911f74d4d4ad/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/setupConfigurationsAndCompilations.kt#L68 build the engine and try again? My guess is that this excludes your module information from the resulting jar. But that's just a guess. Or provide a minimal reproduction sample so i can test that myself?

chippmann avatar Jul 16 '21 10:07 chippmann

I think I might be having a similar issue getting the Exposed library to work:

Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Driver
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:383)
	at java.base/java.lang.Class.forName(Class.java:376)
	at org.jetbrains.exposed.sql.Database$Companion.connect(Database.kt:204)
	at org.jetbrains.exposed.sql.Database$Companion.connect$default(Database.kt:195)
	at com.example.galaxyStream.universe.SubstanceKt.connectDatabase(Substance.kt:162)
	at com.example.galaxyStream.universe.Galaxy._ready(Galaxy.kt:59)
	at godot.com.example.galaxyStream.universe.GalaxyRegistrar$register$1$1$2.invoke(GalaxyRegistrar.kt:19)
	at godot.com.example.galaxyStream.universe.GalaxyRegistrar$register$1$1$2.invoke(GalaxyRegistrar.kt:19)
	at godot.core.KtFunction0.invokeKt$godot_library(Functions.kt:103)
	at godot.core.KtFunction.invoke(Functions.kt:74)
	at godot.core.TransferContext.icall(Native Method)
	at godot.core.TransferContext.callMethod(TransferContext.kt:52)
	at godot.Node.addChild(Node.kt:806)
	at godot.Node.addChild$default(Node.kt:804)
	at com.example.galaxyStream.network.JoinServer._process(JoinServer.kt:266)
	at godot.com.example.galaxyStream.network.JoinServerRegistrar$register$1$1$11.invoke(JoinServerRegistrar.kt:28)
	at godot.com.example.galaxyStream.network.JoinServerRegistrar$register$1$1$11.invoke(JoinServerRegistrar.kt:28)
	at godot.core.KtFunction1.invokeKt$godot_library(Functions.kt:113)
	at godot.core.KtFunction.invoke(Functions.kt:74)
Caused by: java.lang.ClassNotFoundException: java.sql.Driver
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 30 more

This is pretty much just their getting started guide so that might be a minimal reproduction example. Will try commenting out the lines you mentioned but I haven't tried compiling the engine before.

nicola-sorace avatar Sep 15 '22 21:09 nicola-sorace

@chippmann That file seems to have disappeared. Found it here instead, is this the line to comment out now?

https://github.com/utopia-rise/godot-kotlin-jvm/blob/d0b594db3a2a06e1f52879c65e5ad6b1555498c7/kt/godot-library/build.gradle.kts#L44

nicola-sorace avatar Sep 17 '22 17:09 nicola-sorace

@nicola-sorace Did you try to add the sql modules first? Probably this will be enough: jlink --add-modules java.base,java.logging,java.sql --output jre-amd64 but maybe you need additional modules

chippmann avatar Nov 17 '22 14:11 chippmann