List of usage examples for java.net URLClassLoader URLClassLoader
URLClassLoader(URL[] urls, AccessControlContext acc)
From source file:org.evosuite.junit.FooTestClassLoader.java
private static Class<?> loadClass(File javaBinDir) { URLClassLoader urlClassLoader = null; try {//from w w w . j a va2 s . c o m URI javaBinURI = javaBinDir.toURI(); URL javaBinURL = javaBinURI.toURL(); urlClassLoader = new URLClassLoader(new URL[] { javaBinURL }, Foo.class.getClassLoader()); Class<?> clazz = urlClassLoader.loadClass(FOO_TEST_CLASS_NAME); return clazz; } catch (ClassNotFoundException e) { return null; } catch (MalformedURLException e) { return null; } }
From source file:com.moss.schematrax.SchemaUpdater.java
public SchemaUpdater(String prefix, boolean manageTransactions) throws Exception { this.manageTransactions = manageTransactions; if (prefix.equals("")) log.info("Starting SchemaUpdater with default classpath"); else//from w w w .j a v a 2 s .co m log.info("Starting SchemaUpdater with classpath root: " + prefix); updatesLoader = new URLClassLoader(new URL[] {}, this.getClass().getClassLoader()); init(prefix); }
From source file:SerialVersionUID.java
/** * Create a Map<String, ClassVersionInfo> for the jboss dist jars. * /*w w w. j a v a 2 s . c o m*/ * @param jbossHome - * the jboss dist root directory * @return Map<String, ClassVersionInfo> * @throws IOException */ public static Map generateJBossSerialVersionUIDReport(File jbossHome) throws IOException { // Obtain the jars from the /lib, common/ and /server/all locations HashSet jarFiles = new HashSet(); File lib = new File(jbossHome, "lib"); buildJarSet(lib, jarFiles); File common = new File(jbossHome, "common"); buildJarSet(common, jarFiles); File all = new File(jbossHome, "server/all"); buildJarSet(all, jarFiles); URL[] cp = new URL[jarFiles.size()]; jarFiles.toArray(cp); ClassLoader parent = Thread.currentThread().getContextClassLoader(); URLClassLoader completeClasspath = new URLClassLoader(cp, parent); TreeMap classVersionMap = new TreeMap(); Iterator jarIter = jarFiles.iterator(); while (jarIter.hasNext()) { URL jar = (URL) jarIter.next(); try { generateJarSerialVersionUIDs(jar, classVersionMap, completeClasspath, ""); } catch (IOException e) { log.info("Failed to process jar: " + jar); } } return classVersionMap; }
From source file:io.personium.engine.extension.support.ExtensionJarLoader.java
/** * .//from ww w . j a v a 2s .c om * PCS????????????????? getInstance()??? * @param extJarDir Extensionjar?? * @param searchDescend true: ?, false: ???? * @param parentCl * @param filter Extension * @throws IOException Extension???? * @throws PersoniumEngineException */ private ExtensionJarLoader(Path extJarDir, boolean searchDescend, ClassLoader parentCl, ExtensionClassFilter filter) throws IOException, PersoniumEngineException { extensionJarDirectory = extJarDir; searchDescendant = searchDescend; List<URL> jarPaths = getJarPaths(extensionJarDirectory, searchDescendant); classloader = new URLClassLoader(jarPaths.toArray(new URL[] {}), parentCl); scriptableClassSet = loadPrototypeClassSet(jarPaths, filter); }
From source file:org.ngrinder.agent.service.AgentManagerServiceTest.java
@Test public void testCompressAgentFolder() throws IOException, URISyntaxException { URLClassLoader loader = (URLClassLoader) this.getClass().getClassLoader(); URL core = this.getClass().getClassLoader().getResource("lib/ngrinder-core-test.jar"); URL sh = this.getClass().getClassLoader().getResource("lib/ngrinder-sh-test.jar"); URL[] ls = { core, sh };//from w w w . j av a2s .c o m URL[] urls = loader.getURLs(); URL[] allLib = cast(ArrayUtils.addAll(urls, ls)); URLClassLoader child = new URLClassLoader(allLib, this.getClass().getClassLoader()); File agentUpgrade = agentPackageService.createAgentPackage(child, null, null, 10000, null); FileUtils.deleteQuietly(agentUpgrade); }
From source file:com.tower.service.test.SoafwTesterMojo.java
public void execute() throws MojoExecutionException { String flg = test_gen_skip;//from w w w . j a v a 2 s . com this.getLog().info("" + this.getPluginContext()); project = (MavenProject) getPluginContext().get("project"); this.getLog().info("ProjectName: " + project.getName()); File basedir = project.getBasedir(); basedPath = basedir.getAbsolutePath(); artifactId = project.getArtifactId(); this.getLog().info("basedPath:" + basedPath); if ("true".equalsIgnoreCase(flg)) { this.getLog().info("test.gen.skip: " + artifactId); return; } this.getLog().info("start unit test file gen&check: " + artifactId); try { List<String> classpaths = project.getCompileClasspathElements(); List<String> testClasspaths = project.getTestClasspathElements(); URL[] runtimeUrls = new URL[classpaths.size() + testClasspaths.size()]; for (int i = 0; i < classpaths.size(); i++) { String classpath = (String) classpaths.get(i); runtimeUrls[i] = new File(classpath).toURI().toURL(); } for (int i = 0; i < testClasspaths.size(); i++) { String classpath = (String) testClasspaths.get(i); runtimeUrls[classpaths.size() + i] = new File(classpath).toURI().toURL(); } // ?classpath runtimeUrls[classpaths.size()] = new File(basedPath + File.separator + testClasspath).toURI().toURL(); this.cl = new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); } catch (Exception e2) { } String classesDir = basedPath + File.separator + classpath; this.getLog().info(": " + new File(classesDir).exists()); int length = classesDir.length() + 1; // load(classesDir, new File(classesDir), length);// map /** * */ String testClassesDir = basedPath + File.separator + testClasspath; this.getLog().info("?: " + new File(testClassesDir).exists()); length = testClassesDir.length() + 1; // load(testClassesDir, new File(testClassesDir), length);// map int size = defines.size(); String[] definesArray = new String[size]; defines.keySet().toArray(definesArray); if (size == 0) { this.getLog().info("??"); } for (int i = 0; i < size; i++) { boolean hasmethod = false; if (!testImpl.containsKey(definesArray[i] + "Test")) { this.getLog().info("?" + definesArray[i] + "Test"); genTest(basedPath, definesArray[i]); } else {// ? appendTest(definesArray[i]); } } for (int i = 0; i < size; i++) { if (testImpl.containsKey(definesArray[i] + "Test")) { defines.remove(definesArray[i]); } } this.getLog().info("&???" + defines); this.getLog().info("???||?" + testImpl); this.getLog().error("??" + errorImpl); }
From source file:org.lenskit.cli.util.ScriptEnvironment.java
/** * Get the class loader for this script environment. * @return The class loader./* w w w .j a v a2 s . co m*/ */ public ClassLoader getClassLoader() { ClassLoader parent = Thread.currentThread().getContextClassLoader(); if (parent == null) { parent = getClass().getClassLoader(); } if (classpath.isEmpty()) { return parent; } else { URL[] urls = new URL[classpath.size()]; int i = 0; for (String path : classpath) { File file = new File(path); try { urls[i] = file.toURI().toURL(); logger.info("added to classpath: {}", urls[i]); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL", e); } i += 1; } return new URLClassLoader(urls, parent); } }
From source file:org.grouplens.lenskit.cli.ScriptEnvironment.java
/** * Get the class loader for this script environment. * @return The class loader.//from ww w . jav a 2 s . c o m */ public ClassLoader getClassLoader() { ClassLoader parent = Thread.currentThread().getContextClassLoader(); if (parent == null) { parent = getClass().getClassLoader(); } if (classpath.isEmpty()) { return parent; } else { URL[] urls = new URL[classpath.size()]; URI base = new File(".").toURI(); int i = 0; for (URI uri : classpath) { try { urls[i] = base.resolve(uri).toURL(); logger.info("added to classpath: {}", urls[i]); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL", e); } i += 1; } return new URLClassLoader(urls, parent); } }
From source file:org.apache.axis2.classloader.MultiParentClassLoader.java
static ClassLoader copy(ClassLoader source) { if (source instanceof MultiParentClassLoader) { return new MultiParentClassLoader((MultiParentClassLoader) source); } else if (source instanceof URLClassLoader) { return new URLClassLoader(((URLClassLoader) source).getURLs(), source.getParent()); } else {/*w ww . j a v a2 s. co m*/ return new URLClassLoader(new URL[0], source); } }
From source file:com.microsoft.tfs.core.internal.db.ConnectionConfiguration.java
public ConnectionConfiguration(final PersistenceStore cacheStore, final String pathId, final boolean verboseInput) { Check.notNull(cacheStore, "cacheStore"); //$NON-NLS-1$ pathIdentifer = Metadata.SCHEMA_VERSION + "-" + pathId; //$NON-NLS-1$ verbose = verboseInput;/*w w w. jav a 2s .c om*/ configuration = new Configuration(ConnectionConfiguration.class, "/" + DB_PROPS_FILE_NAME); //$NON-NLS-1$ driverClass = configuration.getConfiguration(DRIVER_CONFIG_KEY, DRIVER_DEFAULT); url = configuration.getConfiguration(URL_CONFIG_KEY, URL_DEFAULT); username = configuration.getConfiguration(USERNAME_CONFIG_KEY, USERNAME_DEFAULT); password = configuration.getConfiguration(PASSWORD_CONFIG_KEY, PASSWORD_DEFAULT); final String extraClasspath = configuration.getConfiguration(CLASSPATH_CONFIG_KEY, null); if (url.equals(URL_DEFAULT)) { if (cacheStore instanceof VersionedVendorFilesystemPersistenceStore) { /* * This may still return null if no candidate areas were * lockable. */ databaseDiskDirectory = getDirectoryForDiskDatabase( (VersionedVendorFilesystemPersistenceStore) cacheStore, pathIdentifer); } else { log.warn(MessageFormat.format( "The {0} used to create {1} is not a {2}, which is required to retarget HSQLDB storage (it can only use files). The fallback URL of {3} will be used.", //$NON-NLS-1$ PersistenceStore.class.getName(), ConnectionConfiguration.class.getName(), VersionedVendorFilesystemPersistenceStore.class.getName(), URL_FALLBACK)); } if (databaseDiskDirectory == null) { url = URL_FALLBACK; } else { final File db = new File(databaseDiskDirectory, "teamexplorer"); //$NON-NLS-1$ url = "jdbc:hsqldb:file:" + db.getAbsolutePath(); //$NON-NLS-1$ } } ClassLoader jdbcLoader = getClass().getClassLoader(); if (extraClasspath != null) { final File extraJar = new File(extraClasspath); try { jdbcLoader = new URLClassLoader(new URL[] { extraJar.toURL() }, jdbcLoader); } catch (final MalformedURLException ex) { throw new RuntimeException(ex); } } try { driver = (Driver) jdbcLoader.loadClass(driverClass).newInstance(); } catch (final Throwable t) { throw new RuntimeException(MessageFormat.format("unable to load specified jdbc driver class [{0}]", //$NON-NLS-1$ driverClass), t); } if (verbose) { System.out.println(MessageFormat.format("DB connection URL: [{0}]", url)); //$NON-NLS-1$ System.out.println(MessageFormat.format("DB driver class: [{0}] (version {1}.{2})", //$NON-NLS-1$ driver.getClass().getName(), Integer.toString(driver.getMajorVersion()), Integer.toString(driver.getMinorVersion()))); System.out.println(MessageFormat.format("DB driver loaded from: [{0}]", //$NON-NLS-1$ getDriverClassURL().toExternalForm())); } }