Hi every One,
I got a small problem with class loading from jar in kotlin ( 1.3.71 + jdk 14 ( as runtime )). I got old library written in java 1.6, which have Field class which I would like to load. When I create class implicit there is no problem it is created, but when I want to create the same class using class loader it fails ( ClassNotFoundException ).
fun main(args: Array<String>) {
val field = com.dom.Field(1,1)
val c = field.javaClass.classLoader
c.loadClass("Field")
val reflections = Reflections(ConfigurationBuilder()
.addClassLoader(c)
.setScanners(SubTypesScanner(false /* don't exclude Object.class */), ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(*classLoadersList.toTypedArray()))
.filterInputsBy(FilterBuilder().include(FilterBuilder.prefix("com.com"))))
}
first list of main is running, next liste also, but thirhd c.loadClass(“Field”) failed and thourgh out exception.
Exception in thread “main” java.lang.ClassNotFoundException: Field
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at MainKt.main(main.kt:24)
Funnty thing ,when I do the same on jdk1.8 it works correctly
Do you have any ideas what could possibly be the problem ?