src/main/java/org/jboss/util/Classes.java
/**
    * Force the given class to be loaded fully.
    *
    * <p>This method attempts to locate a static method on the given class
    *    the attempts to invoke it with dummy arguments in the hope that
    *    the virtual machine will prepare the class for the method call and
    *    call all of the static class initializers.
    *
    * @param type    Class to force load.
    *
    * @throws NullArgumentException    Type is <i>null</i>.
    */
Force the given class to be loaded fully.
This method attempts to locate a static method on the given class
the attempts to invoke it with dummy arguments in the hope that
the virtual machine will prepare the class for the method call and
call all of the static class initializers.

@param type    Class to force load.

@throws NullArgumentException    Type is null.
Force the given class to be loaded fully . This method attempts to locate a static method on the given class the attempts to invoke it with dummy arguments in the hope that the virtual machine will prepare the class for the method call and call all of the static class initializers . @param type Class to force load . @throws NullArgumentException Type is null .
public static void forceLoad(final Class type)
   {
      if (type == null)
         throw new NullArgumentException("type");
      if (type.isPrimitive()) return;
      String packageName = Classes.getPackageName(type);
      if (packageName.startsWith("java.") ||
         packageName.startsWith("javax."))
      {
         return;
      }
      try
      {
         Method methods[] = type.getDeclaredMethods();
         Method method = null;
         for (int i = 0; i < methods.length; i++)
         {
            int modifiers = methods[i].getModifiers();
            if (Modifier.isStatic(modifiers))
            {
               method = methods[i];
               break;
            }
         }
         if (method != null)
         {
            method.invoke(null, (Object[]) null);
         }
         else
         {
            type.newInstance();
         }
      }
      catch (Exception ignore)
      {
         ThrowableHandler.add(ignore);
      }
   }
public static void forceLoad ( final Class type ) { if ( type == null ) throw new NullArgumentException ( "type" ) ; if ( type . isPrimitive ( ) ) return ; String packageName = Classes . getPackageName ( type ) ; if ( packageName . startsWith ( "java." ) || packageName . startsWith ( "javax." ) ) { return ; } try { Method methods [ ] = type . getDeclaredMethods ( ) ; Method method = null ; for ( int i = 0 ; i < methods . length ; i ++ ) { int modifiers = methods [ i ] . getModifiers ( ) ; if ( Modifier . isStatic ( modifiers ) ) { method = methods [ i ] ; break ; } } if ( method != null ) { method . invoke ( null , ( Object [ ] ) null ) ; } else { type . newInstance ( ) ; } } catch ( Exception ignore ) { ThrowableHandler . add ( ignore ) ; } }
Force the given class to be loaded fully.
Force the given class to be loaded fully .
// don't attempt to force primitives to load // don't attempt to force java.* classes to load // System.out.println("package name: " + packageName); // System.out.println("forcing class to load: " + type);