Class DefinePackageHelper


  • public class DefinePackageHelper
    extends java.lang.Object
    Helper class for invoking ClassLoader.defineClass(String,byte[],int,int).
    Since:
    3.22
    • Constructor Detail

      • DefinePackageHelper

        private DefinePackageHelper()
    • Method Detail

      • definePackage

        public static void definePackage​(java.lang.String className,
                                         java.lang.ClassLoader loader)
                                  throws CannotCompileException
        Defines a new package. If the package is already defined, this method performs nothing.

        You do not necessarily need to call this method. If this method is called, then getPackage() on the Class object returned by toClass() will return a non-null object.

        The jigsaw module introduced by Java 9 has broken this method. In Java 9 or later, the VM argument --add-opens java.base/java.lang=ALL-UNNAMED has to be given to the JVM so that this method can run.

        Parameters:
        loader - the class loader passed to toClass() or the default one obtained by getClassLoader().
        className - the package name.
        Throws:
        CannotCompileException
        See Also:
        Class.getClassLoader(), CtClass.toClass()