Task: load any application class using a custom class loader (CustomClassLoader) in Java 17 style (with module-info.java).
Modules (declared via module-info.java):
manual.onemodule.j17style:Main- a class containing themainmethod, where an instance of theCustomClassLoaderclass is created, theCatclass is loaded using it, creating an instance of the classCatand calling theCat::talkmethod;Cat- loadable class with thetalkmethod, which prints the string "Meow" tostdout;CustomClassLoader- a class that is an implementation of a custom class loader.
Using
classpaththe results are the same as in Java 17. Manual Loading (Java 8 style).
Using modulepath:
java17 -p . -m manual.onemodule.j17styleOutput:
Main Class Module is module manual.onemodule.j17style
Cat Class Module is unnamed module @f6f4d33
Main Class ClassLoader is jdk.internal.loader.ClassLoaders$AppClassLoader@4554617c
Cat Class ClassLoader is ru.ispras.j17.manual.onemodule.j17style.CustomClassLoader@5acf9800
Meow- Regarding Java 17. Manual Loading (Java 8 style) is different with the module name
manual.onemodule. j17stylein thejarfile, which is anchored withmodule-info .java, so this module is considered an Application Module, and not an Automatic Module.
Same as in Java 17. Manual Loading (Java 8 style).
.jpg)