List of usage examples for java.net URLClassLoader URLClassLoader
URLClassLoader(URL[] urls, AccessControlContext acc)
From source file:org.artificer.integration.ExtensionFactory.java
/** * Loads any custom extensions. These can be contributed via the standard Java service loading mechanism * or through custom jars in the dir identified through sramp.extension.customDir *//*ww w . j a va 2 s .c o m*/ private static void loadExtended() { // First load via the standard ServiceRegistry mechanism. Set<ArtifactTypeDetector> extendedTypeDetectors = ServiceRegistryUtil .getServices(ArtifactTypeDetector.class); typeDetectors.addAll(extendedTypeDetectors); Set<ArtifactBuilderProvider> extendedBuilderProviders = ServiceRegistryUtil .getServices(ArtifactBuilderProvider.class); builderProviders.addAll(extendedBuilderProviders); // Allow users to provide a directory path where we will check for JARs that // contain extension implementations. Collection<ClassLoader> loaders = new LinkedList<ClassLoader>(); String customDirPath = System.getProperty(ArtificerConstants.ARTIFICER_CUSTOM_EXTENSION_DIR); if (customDirPath != null && customDirPath.trim().length() > 0) { File directory = new File(customDirPath); if (directory.isDirectory()) { List<URL> jarURLs = new ArrayList<URL>(); Collection<File> jarFiles = FileUtils.listFiles(directory, new String[] { "jar" }, false); for (File jarFile : jarFiles) { try { URL jarUrl = jarFile.toURI().toURL(); jarURLs.add(jarUrl); } catch (MalformedURLException e) { } } URL[] urls = jarURLs.toArray(new URL[jarURLs.size()]); ClassLoader jarCL = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); loaders.add(jarCL); } } for (ClassLoader loader : loaders) { for (ArtifactTypeDetector typeDetector : ServiceLoader.load(ArtifactTypeDetector.class, loader)) { typeDetectors.add(typeDetector); } for (ArtifactBuilderProvider builderProvider : ServiceLoader.load(ArtifactBuilderProvider.class, loader)) { builderProviders.add(builderProvider); } } }
From source file:org.overlord.sramp.integration.ExtensionFactory.java
/** * Loads any custom extensions. These can be contributed via the standard Java service loading mechanism * or through custom jars in the dir identified through sramp.extension.customDir *///from w ww .ja va 2 s . c o m private static void loadExtended() { // First load via the standard ServiceRegistry mechanism. Set<ArtifactTypeDetector> extendedTypeDetectors = ServiceRegistryUtil .getServices(ArtifactTypeDetector.class); typeDetectors.addAll(extendedTypeDetectors); Set<ArtifactBuilderProvider> extendedBuilderProviders = ServiceRegistryUtil .getServices(ArtifactBuilderProvider.class); builderProviders.addAll(extendedBuilderProviders); // Allow users to provide a directory path where we will check for JARs that // contain extension implementations. Collection<ClassLoader> loaders = new LinkedList<ClassLoader>(); String customDirPath = System.getProperty(SrampConstants.SRAMP_CUSTOM_EXTENSION_DIR); if (customDirPath != null && customDirPath.trim().length() > 0) { File directory = new File(customDirPath); if (directory.isDirectory()) { List<URL> jarURLs = new ArrayList<URL>(); Collection<File> jarFiles = FileUtils.listFiles(directory, new String[] { "jar" }, false); //$NON-NLS-1$ for (File jarFile : jarFiles) { try { URL jarUrl = jarFile.toURI().toURL(); jarURLs.add(jarUrl); } catch (MalformedURLException e) { } } URL[] urls = jarURLs.toArray(new URL[jarURLs.size()]); ClassLoader jarCL = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); loaders.add(jarCL); } } for (ClassLoader loader : loaders) { for (ArtifactTypeDetector typeDetector : ServiceLoader.load(ArtifactTypeDetector.class, loader)) { typeDetectors.add(typeDetector); } for (ArtifactBuilderProvider builderProvider : ServiceLoader.load(ArtifactBuilderProvider.class, loader)) { builderProviders.add(builderProvider); } } }
From source file:org.cmg.ml.sam.SamProjectHelper.java
public static Class<?> loadClassFromProject(ClassLoader parentClassLoader, Resource resource, IProject project) throws CoreException, MalformedURLException, ClassNotFoundException { String[] classPathEntries = JavaRuntime.computeDefaultRuntimeClassPath(JavaCore.create(project)); // URL url = JavaCore.create(project).getOutputLocation().toFile(). // List<URL> urlList = new ArrayList<URL>(); // for (int i = 0; i < classPathEntries.length; i++) { String entry = classPathEntries[0]; IPath path = new Path(entry); URL url = path.toFile().toURI().toURL(); // urlList.add(url); // }// ww w . ja va2 s. c o m // ClassLoader parentClassLoader = project.getClass().getClassLoader(); // URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]); // URLClassLoader classLoader = new URLClassLoader(urls, cLoader); URLClassLoader classLoader = new URLClassLoader(new URL[] { url }, parentClassLoader); Class<?> clazz = classLoader.loadClass(SamProjectHelper.getPackageFolder(resource).replace('/', '.') + "." + SamProjectHelper.getClassName(resource)); return clazz; }
From source file:com.thoughtworks.go.agent.common.util.JarUtil.java
public static URLClassLoader getClassLoaderFromJar(File aJarFile, Predicate<JarEntry> extractFilter, File outputTmpDir, ClassLoader parentClassLoader, Class... allowedClasses) { List<File> urls = new ArrayList<>(); urls.add(aJarFile);// ww w . j a va 2s . c o m urls.addAll(extractFilesInLibDirAndReturnFiles(aJarFile, extractFilter, outputTmpDir)); ParentClassAccessFilteringClassloader filteringClassloader = new ParentClassAccessFilteringClassloader( parentClassLoader, allowedClasses); return new URLClassLoader(toURLs(urls), filteringClassloader); }
From source file:com.wavemaker.app.build.maven.plugin.handler.SwaggerDocGenerationHandler.java
@Override public void handle() { try {/*from www . ja v a 2 s . c om*/ urlClassLoader = new URLClassLoader(classPathURLs, Thread.currentThread().getContextClassLoader()); List<Folder> serviceFolders = servicesFolder.list().folders().fetchAll(); if (serviceFolders.size() > 0) { for (Folder serviceFolder : serviceFolders) { generateSwaggerDoc(serviceFolder); } } } finally { if (urlClassLoader != null) { try { urlClassLoader.close(); } catch (IOException e) { logger.warn("Failed to close classloader"); } } } }
From source file:org.bonitasoft.engine.business.data.ClassloaderRefresher.java
/** * @param clientZipContent//from ww w .ja v a 2s. c o m * @param contextClassLoader * @param modelClass * @param fsFolderToPutJars * @return the newly created classloader with newly loaded class, if found. * @throws java.io.IOException * @throws java.net.MalformedURLException */ public ClassLoader loadClientModelInClassloader(final byte[] clientZipContent, final ClassLoader contextClassLoader, final String modelClass, final File fsFolderToPutJars) throws IOException, MalformedURLException { final Map<String, byte[]> ressources = IOUtils.unzip(clientZipContent); final List<URL> urls = new ArrayList<URL>(); for (final Entry<String, byte[]> e : ressources.entrySet()) { final File file = new File(fsFolderToPutJars, e.getKey()); if (file.getName().endsWith(".jar")) { if (file.getName().contains("model")) { try { contextClassLoader.loadClass(modelClass); } catch (final ClassNotFoundException e1) { FileUtils.writeByteArrayToFile(file, e.getValue()); urls.add(file.toURI().toURL()); } } if (file.getName().contains("dao")) { try { contextClassLoader.loadClass(modelClass + "DAO"); } catch (final ClassNotFoundException e1) { FileUtils.writeByteArrayToFile(file, e.getValue()); urls.add(file.toURI().toURL()); } } if (file.getName().contains("javassist")) { try { contextClassLoader.loadClass("javassist.util.proxy.MethodFilter"); } catch (final ClassNotFoundException e1) { FileUtils.writeByteArrayToFile(file, e.getValue()); urls.add(file.toURI().toURL()); } } } } ClassLoader classLoaderWithBDM = contextClassLoader; if (!urls.isEmpty()) { classLoaderWithBDM = new URLClassLoader(urls.toArray(new URL[urls.size()]), contextClassLoader); } return classLoaderWithBDM; }
From source file:eu.stratosphere.yarn.Utils.java
private static void addPathToConfig(Configuration conf, File path) { // chain-in a new classloader URL fileUrl = null;/* w w w. j a v a 2 s .c om*/ try { fileUrl = path.toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Erroneous config file path", e); } URL[] urls = { fileUrl }; ClassLoader cl = new URLClassLoader(urls, conf.getClassLoader()); conf.setClassLoader(cl); }
From source file:org.renjin.cli.build.TestRun.java
private ClasspathPackageLoader createPackageLoader() { try {//from www. jav a 2s. com URL packageUnderTestUrl = stagingDir.toURI().toURL(); URLClassLoader classLoader = new URLClassLoader(new URL[] { packageUnderTestUrl }, getClass().getClassLoader()); return new ClasspathPackageLoader(classLoader); } catch (Exception e) { throw new BuildException("Exception creating package loader", e); } }
From source file:com.heimuheimu.runningtask.task.service.support.SimpleURLClassLoaderFactory.java
/** * ?ClassLoader/*from ww w .j a v a2 s . c o m*/ * <p>? * * @see {@link #setCommonResource(String)} * @see {@link #parentClassLoader} */ @PostConstruct public void init() { if (commonResource != null && !commonResource.isEmpty()) { long startTime = System.currentTimeMillis(); URL[] urls = getURLArray(commonResource); parentClassLoader = new URLClassLoader(urls, parentClassLoader); LOG.info("Create parent URLClassLoader success. Cost: `{}` ms. Common resource path: `{}`", System.currentTimeMillis() - startTime, commonResource); } }
From source file:com.clican.pluto.orm.dynamic.impl.DynamicClassLoader.java
public synchronized void refreshClasses() throws ClassNotFoundException { URL[] urls = urlClassLoader.getURLs(); urlClassLoader = new URLClassLoader(urls, urlClassLoader.getParent()); File file = new File(tempORMCfgPojoFolder); if (!file.exists()) { file.mkdirs();// w w w. j a va 2 s . co m } loadedDynamicClasses.clear(); loadAllClasses(file); }