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 themain
method, where an instance of theCustomClassLoader
class is created, theCat
class is loaded using it, creating an instance of the classCat
and calling theCat::talk
method;Cat
- loadable class with thetalk
method, which prints the string "Meow" tostdout
;CustomClassLoader
- a class that is an implementation of a custom class loader.
Using
classpath
the results are the same as in Java 17. Manual Loading (Java 8 style).
Using modulepath
:
java17 -p . -m manual.onemodule.j17style
Output:
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. j17style
in thejar
file, 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).