List of usage examples for java.net URLClassLoader URLClassLoader
URLClassLoader(URL[] urls, AccessControlContext acc)
From source file:com.linecorp.armeria.server.http.jetty.JettyServiceTest.java
static WebAppContext newWebAppContext() throws MalformedURLException { final WebAppContext handler = new WebAppContext(); handler.setContextPath("/"); handler.setBaseResource(Resource.newClassPathResource("/tomcat_service")); handler.setClassLoader(new URLClassLoader( new URL[] { Resource.newClassPathResource("/tomcat_service/WEB-INF/lib/hello.jar").getURI().toURL() }, JettyService.class.getClassLoader())); handler.addBean(new ServletContainerInitializersStarter(handler), true); handler.setAttribute("org.eclipse.jetty.containerInitializers", Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null))); return handler; }
From source file:com.ifunshow.dbc.util.DBHelper.java
public static URLClassLoader decideDriverLoader(String dbType, String dbVersion) throws MalformedURLException { URL[] urls = null;/*w w w . ja va 2 s . co m*/ JarUtil ju = new JarUtil(JarUtil.class); String jarPath = ju.getJarPath() + File.separator + "jdbcjar" + File.separator; System.out.println("jarPath==>" + jarPath); if ("oracle".equalsIgnoreCase(StringUtils.trim(dbType))) { urls = new URL[1]; if ("8".equalsIgnoreCase(dbVersion)) { urls[0] = new File(jarPath + "oracle_classes12.jar").toURL(); } else { urls[0] = new File(jarPath + "oracle_ojdbc6.jar").toURL(); } } else if ("teradata".equalsIgnoreCase(StringUtils.trim(dbType))) { urls = new URL[2]; urls[0] = new File(jarPath + "teradata_tdgssconfig.jar").toURL(); urls[1] = new File(jarPath + "teradata_terajdbc4.jar").toURL(); } else if ("db2".equalsIgnoreCase(StringUtils.trim(dbType))) { urls = new URL[2]; if ("8".equalsIgnoreCase(dbVersion)) { urls[0] = new File(jarPath + "db2_db2jcc-v8.jar").toURL(); urls[1] = new File(jarPath + "db2_db2jcc_license_cu-v8.jar").toURL(); } else { urls[0] = new File(jarPath + "db2_db2jcc-v9.7.jar").toURL(); urls[1] = new File(jarPath + "db2_db2jcc_license_cu-v9.7.jar").toURL(); } } else if ("mysql".equalsIgnoreCase(StringUtils.trim(dbType))) { urls = new URL[1]; urls[0] = new File(jarPath + "mysql_connector_5.1.15_bin.jar").toURL(); } return new URLClassLoader(urls, ClassLoader.getSystemClassLoader()); }
From source file:org.onecmdb.core.internal.job.workflow.CiToJavaObject.java
private ClassLoader getClassLoader() { if (this.urls != null) { return (new URLClassLoader((URL[]) this.urls.toArray(), this.getClass().getClassLoader())); }/*from w w w .j ava 2s. c o m*/ return (this.getClass().getClassLoader()); }
From source file:com.evolveum.midpoint.common.LocalizationServiceImpl.java
public void init() { URL url = buildMidpointHomeLocalizationFolderUrl(); ClassLoader classLoader = new URLClassLoader(new URL[] { url }, null); sources.add(buildSource("Midpoint", classLoader)); sources.add(buildSource(SchemaConstants.BUNDLE_NAME, classLoader)); sources.add(buildSource("localization/Midpoint", null)); sources.add(buildSource(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, null)); // model security messages as fallback ResourceBundleMessageSource modelSecurity = new CachedResourceBundleMessageSource(); modelSecurity.setBasename("com.evolveum.midpoint.security"); sources.add(modelSecurity);/*from w w w . j ava2 s . c om*/ // spring security messages as a fallback ResourceBundleMessageSource springSecurity = new CachedResourceBundleMessageSource(); springSecurity.setBasename("org.springframework.security.messages"); sources.add(springSecurity); }
From source file:org.codehaus.plexus.archiver.zip.PlexusIoZipFileResourceCollection.java
protected Iterator<PlexusIoResource> getEntries() throws IOException { final File f = getFile(); if (f == null) { throw new IOException("The zip file has not been set."); }/*from w ww . j a v a 2s .c o m*/ final URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { f.toURI().toURL() }, null) { public URL getResource(String name) { return findResource(name); } }; final URL url = new URL("jar:" + f.toURI().toURL() + "!/"); final ZipFile zipFile = new ZipFile(f, charset != null ? charset.name() : "UTF8"); final Enumeration<ZipArchiveEntry> en = zipFile.getEntriesInPhysicalOrder(); return new ZipFileResourceIterator(en, url, zipFile, urlClassLoader); }
From source file:org.overlord.dtgov.services.deploy.DeployerFactory.java
/** * Loads any dtgov deployers. These can be contributed via the standard Java * service loading mechanism.//w w w.ja va 2 s . co m */ private static void loadDeployers() { // First load via the standard ServiceRegistry mechanism. Set<DeployerProvider> providers = ServiceRegistryUtil.getServices(DeployerProvider.class); for (DeployerProvider provider : providers) { Map<String, Deployer> deployers_provider = provider.createDeployers(); if (deployers_provider != null && !deployers_provider.isEmpty()) { deployers.putAll(deployers_provider); } } // Allow users to provide a directory path where we will check for JARs // that // contain Deployer implementations. Collection<ClassLoader> loaders = new LinkedList<ClassLoader>(); String customDeployerDirPath = System.getProperty(DTGovConstants.DTGOV_CUSTOM_DEPLOYERS_DIR); if (customDeployerDirPath != null && customDeployerDirPath.trim().length() > 0) { File directory = new File(customDeployerDirPath); 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); } } // Now load all of these contributed DeployerProvider implementations for (ClassLoader loader : loaders) { for (DeployerProvider provider : ServiceLoader.load(DeployerProvider.class, loader)) { Map<String, Deployer> deployers_provider = provider.createDeployers(); if (deployers_provider != null && !deployers_provider.isEmpty()) { deployers.putAll(deployers_provider); } } } }
From source file:jp.terasoluna.fw.batch.unit.util.ClassLoaderUtils.java
/** * <pre>// w ww. j ava 2 s .c o m * ??????url??????? * ??????? * * ???? * ???????????? * {@link #resetClassLoader()}??????? * </pre> * * @param url ? */ public static void addClassPath(URL url) { Assert.notNull(url); ClassLoader cl = getClassLoader(); URLClassLoader newCl = null; if (cl instanceof URLClassLoader) { @SuppressWarnings("resource") URLClassLoader ucl = (URLClassLoader) cl; newCl = new URLClassLoader(ucl.getURLs(), cl); } else { newCl = new URLClassLoader(null, cl); } Method method = getAddURLMethod(); try { method.invoke(newCl, url); } catch (Exception e) { throw new UTRuntimeException(e); } previousClassLoader = cl; setClassLoader(newCl); }
From source file:com.samczsun.helios.handler.addons.JarLauncher.java
@Override public void run(File file) { JarFile jarFile = null;//from www . j ava 2s . c o m InputStream inputStream = null; try { System.out.println("Loading addon: " + file.getAbsolutePath()); jarFile = new JarFile(file); ZipEntry entry = jarFile.getEntry("addon.json"); if (entry != null) { inputStream = jarFile.getInputStream(entry); JsonObject jsonObject = JsonObject .readFrom(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); String main = jsonObject.get("main").asString(); URL[] url = new URL[] { file.toURI().toURL() }; ClassLoader classLoader = AccessController .doPrivileged((PrivilegedAction<ClassLoader>) () -> new URLClassLoader(url, Helios.class.getClassLoader())); Class<?> clazz = Class.forName(main, true, classLoader); if (Addon.class.isAssignableFrom(clazz)) { Addon addon = Addon.class.cast(clazz.newInstance()); registerAddon(addon.getName(), addon); } else { throw new IllegalArgumentException("Addon main does not extend Addon"); } } else { throw new IllegalArgumentException("No addon.json found"); } } catch (Exception e) { ExceptionHandler.handle(e); } finally { IOUtils.closeQuietly(jarFile); IOUtils.closeQuietly(inputStream); } }
From source file:hudson.jbpm.ProcessClassLoaderCache.java
public synchronized ClassLoader getClassLoader(ProcessDefinition def) throws IOException { ClassLoader cl = cache.get(def.getId()); if (cl == null) { File pdCache = new File(cacheRoot, Long.toString(def.getId())); if (!pdCache.exists()) { FileDefinition fd = def.getFileDefinition(); for (Map.Entry<String, byte[]> entry : ((Map<String, byte[]>) fd.getBytesMap()).entrySet()) { File f = new File(pdCache, entry.getKey()); f.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(f); IOUtils.copy(new ByteArrayInputStream(entry.getValue()), fos); fos.close();//from w w w . j a v a2s. c o m } } cl = new URLClassLoader(new URL[] { new URL(pdCache.toURI().toURL(), "classes/") }, Hudson.getInstance().getPluginManager().uberClassLoader) { @Override public Class<?> loadClass(String name) throws ClassNotFoundException { System.out.println(name); return super.loadClass(name); } }; cache.put(def.getId(), cl); } return cl; }
From source file:com.kelveden.rastajax.cli.Runner.java
private static Set<FlatResource> loadRepresentation(List<URL> urls, String packages) { final ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[] {}), Runner.class.getClassLoader()); final ClassLoaderRootResourceScanner scanner = new ClassLoaderRootResourceScanner(classLoader, packages.split(",")).allowInterfaceInheritance(); return RestDescriber.describeApplication(scanner.scan(), new FlatRepresentationBuilder()); }