List of usage examples for java.net URLClassLoader URLClassLoader
public URLClassLoader(URL[] urls)
From source file:org.pentaho.aggdes.test.util.TestUtils.java
public static void registerDriver(final String jdbcDriverClasspath, final String jdbcDriverClassname) throws Exception { Driver newDriver;/* w ww. ja v a 2 s .c o m*/ if (jdbcDriverClasspath != null && !jdbcDriverClasspath.equals("")) { URLClassLoader urlLoader = new URLClassLoader(new URL[] { new URL(jdbcDriverClasspath) }); Driver d = (Driver) Class.forName(jdbcDriverClassname, true, urlLoader).newInstance(); newDriver = new DriverShim(d); } else { newDriver = (Driver) Class.forName(jdbcDriverClassname).newInstance(); } DriverManager.registerDriver(newDriver); registeredDrivers.put(jdbcDriverClasspath + ":" + jdbcDriverClassname, newDriver); //$NON-NLS-1$ }
From source file:net.adrianromero.tpv.forms.AppViewConnection.java
/** Creates a new instance of AppViewConnection */ public AppViewConnection() throws BasicException { // Leo la configuracion m_config = new AppConfig(); m_config.load();// ww w.j av a 2s.com m_s = null; // Inicializo la conexion contra la base de datos. try { ClassLoader cloader = new URLClassLoader( new URL[] { new File(getProperty("db.driverlib")).toURI().toURL() }); DriverManager.registerDriver(new DriverWrapper( (Driver) Class.forName(getProperty("db.driver"), true, cloader).newInstance())); String sDBUser = getProperty("db.user"); String sDBPassword = getProperty("db.password"); if (sDBUser != null && sDBPassword != null && sDBPassword.startsWith("crypt:")) { // La clave esta encriptada. AltEncrypter cypher = new AltEncrypter("cypherkey" + sDBUser); sDBPassword = cypher.decrypt(sDBPassword.substring(6)); } m_s = new Session(getProperty("db.URL"), sDBUser, sDBPassword); // BasicDataSource ds = new BasicDataSource(); // ds.setUrl(getProperty("db.URL")); // ds.setUsername(sDBUser); // ds.setPassword(sDBPassword); // // m_ds = ds; } catch (InstantiationException e) { throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), e); } catch (IllegalAccessException eIA) { throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eIA); } catch (MalformedURLException eMURL) { throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eMURL); } catch (ClassNotFoundException eCNF) { throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eCNF); } catch (SQLException eSQL) { throw new BasicException(AppLocal.getIntString("message.databaseconnectionerror"), eSQL); } }
From source file:org.echocat.redprecursor.impl.sun.compilertree.SunNodeFactoryIntegrationTest.java
private void executeMethodIn(File classFile) throws Throwable { final URLClassLoader loader = new URLClassLoader(new URL[] { classFile.getParentFile().toURI().toURL() }); final Class<?> testClass = loader.loadClass("Test"); final Object test = testClass.newInstance(); final Method callMethod = testClass.getMethod("call", String.class, Integer.class); try {/* ww w .ja va 2s . c om*/ callMethod.invoke(test, new Object[] { "abc", 2 }); } catch (InvocationTargetException e) { throw e.getTargetException(); } }
From source file:com.kelveden.rastajax.core.DynamicClassCompiler.java
/** * Constructor.//from w ww . j av a 2s.c o m * * @param workingFolder * The folder which will be used to create source files and compiled class files. */ public DynamicClassCompiler(final File workingFolder) { this.workingFolder = workingFolder; try { final URL classDirectoryURL = new URL("file://" + workingFolder.getAbsolutePath() + "/"); classLoader = new URLClassLoader(new URL[] { classDirectoryURL }); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.hortonworks.registries.schemaregistry.client.ClassLoaderCache.java
public ClassLoaderCache(final SchemaRegistryClient schemaRegistryClient) { this.schemaRegistryClient = schemaRegistryClient; CacheLoader<String, ClassLoader> cacheLoader = new CacheLoader<String, ClassLoader>() { @Override/*w ww. j av a 2 s . co m*/ public ClassLoader load(String fileId) throws Exception { File file = getFile(fileId); return new URLClassLoader(new URL[] { file.toURI().toURL() }); } }; SchemaRegistryClient.Configuration configuration = schemaRegistryClient.getConfiguration(); loadingCache = CacheBuilder.newBuilder() .maximumSize( configuration.getValue(SchemaRegistryClient.Configuration.CLASSLOADER_CACHE_SIZE.name())) .expireAfterAccess( configuration.getValue( SchemaRegistryClient.Configuration.CLASSLOADER_CACHE_EXPIRY_INTERVAL_SECS.name()), TimeUnit.SECONDS) .build(cacheLoader); localJarsDir = new File((String) schemaRegistryClient.getConfiguration() .getValue(SchemaRegistryClient.Configuration.LOCAL_JAR_PATH.name())); if (!localJarsDir.exists()) { if (!localJarsDir.mkdirs()) { throw new RuntimeException( "Could not create given local jar storage dir: [" + localJarsDir.getAbsolutePath() + "]"); } } }
From source file:org.impalaframework.classloader.URLClassRetriever.java
public URLClassRetriever(File[] files) { super();// w w w . jav a2 s . co m Assert.notNull(files, "files cannot be null"); this.urls = URLUtils.createUrls(files); this.urlClassLoader = new URLClassLoader(urls); }
From source file:neembuu.uploader.zip.generator.NUZipFileGenerator.java
private static URLClassLoader l(String[] modules, Path pth) { try {//from w ww. j av a2 s .co m URL[] u = new URL[modules.length]; for (int i = 0; i < u.length; i++) { u[i] = pth.resolve("modules/" + modules[i] + "/build/").toUri().toURL(); } return new URLClassLoader(u); } catch (Exception a) { throw new IllegalStateException(a); } }
From source file:com.github.mbenson.privileged.ant.PrivilegedTask.java
protected FilesystemWeaver createWeaver() { Validate.notNull(getTarget(), "target"); final Path p = new Path(getProject()); final Path cp = getClasspath(); if (cp != null) { p.add(cp);//from w w w . j a v a 2 s . c om } p.add(Path.systemClasspath); log("Using " + p.toString(), Project.MSG_DEBUG); final ClassLoader loader = new URLClassLoader(URLArray.fromPaths(Arrays.asList(p.list()))); return new FilesystemWeaver(getPolicy(), loader, getTarget()) { @Override protected boolean permitMethodWeaving(AccessLevel accessLevel) { return getAccessLevel().compareTo(accessLevel) <= 0; } }.loggingTo(new Log() { @Override public void info(String message) { log(message); } @Override public void error(String message) { log(message, Project.MSG_ERR); } @Override public void debug(String message) { log(message, Project.MSG_DEBUG); } @Override public void verbose(String message) { log(message, Project.MSG_VERBOSE); } @Override public void warn(String message) { log(message, Project.MSG_WARN); } }); }
From source file:org.echocat.locela.api.java.messages.FileAccessorClassLoaderBasedUnitTest.java
@Test public void testEquals() throws Exception { assertThat(//from w ww .jav a 2 s . c om ACCESSOR.equals(new ClassLoaderBased(FileAccessorClassLoaderBasedUnitTest.class.getClassLoader())), is(true)); assertThat(ACCESSOR.equals(new ClassLoaderBased(new URLClassLoader(new URL[0]))), is(false)); assertThat(classPathFileAccessor() .equals(new ClassLoaderBased(Thread.currentThread().getContextClassLoader())), is(true)); }
From source file:org.apache.openjpa.eclipse.util.PCEnhancerHelperTest.java
public void testEnhancingAClassThatIsNotAnEntity() throws Exception { if (true)//from w w w.ja v a 2s . c om return; String className = "NotToEnhance"; ClassLoader classLoader = new URLClassLoader(new URL[] { targetDir.toURI().toURL() }); PCEnhancerHelper eh = new PCEnhancerHelperImpl(classLoader); boolean r = checkEnhance(eh, className); Assert.assertFalse(r); // NOT enhanced! }