private static List<Module> runDefineModules(String moduleFile, ClassFileFactory factory) { File stdlibJar = CompilerPathUtil.getRuntimePath(); GeneratedClassLoader loader; if (stdlibJar != null) { try { loader = new GeneratedClassLoader( factory, new URLClassLoader( new URL[] {stdlibJar.toURI().toURL()}, AllModules.class.getClassLoader())); } catch (MalformedURLException e) { throw new RuntimeException(e); } } else { loader = new GeneratedClassLoader( factory, K2JVMCompileEnvironmentConfiguration.class.getClassLoader()); } try { Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS); final Method method = namespaceClass.getDeclaredMethod("project"); if (method == null) { throw new CompileEnvironmentException( "Module script " + moduleFile + " must define project() function"); } method.setAccessible(true); method.invoke(null); ArrayList<Module> answer = new ArrayList<Module>(AllModules.modules.get()); AllModules.modules.get().clear(); return answer; } catch (Exception e) { throw new ModuleExecutionException(e); } finally { loader.dispose(); } }