/** * Create an Object via reflection (using the specified {@link ClassLoader}). * * @param className The name of the class to instantiate. * @param classLoader The {@link ClassLoader} to use to load the class. * @param constructorParameterList The set of parameters to pass to the constructor * * @return A new instance of the class specified by the className * * @throws ClassNotFoundException if the class is not found * @throws NoSuchMethodException if there is no such constructor * @throws InstantiationException if it failed to instantiate * @throws IllegalAccessException if security doesn't allow the call * @throws InvocationTargetException if the constructor failed */ public static Object createObject(String className, ClassLoader classLoader, Object... constructorParameterList) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { Class<?> clazz = Class.forName(className, true, classLoader); Class<?>[] parameterTypes = getClassArrayFromObjectArray(constructorParameterList); Constructor<?> con = ReflectionHelper.getCompatibleConstructor(clazz, parameterTypes); return con.newInstance(constructorParameterList); }